From 780a2e4aec72cf9098d24b1bd6a59166c30ff0b6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 16 Aug 2017 13:58:55 +1000 Subject: [PATCH] Bug 1390428 (part 4) - Remove still more nsXPIDLCString local variables. r=erahm. These are all easy cases where an nsXPIDLCString local variable is set via getter_Copies() and then is null checked. The patch uses IsVoid() to replace the null checks (and get() and EqualsLiteral() calls to replace any implicit conversions). --HG-- extra : rebase_source : 484ad42a7816b34b86afbe072e04ba131c1619c6 --- netwerk/base/nsIOService.cpp | 4 ++-- netwerk/cache2/CacheEntry.cpp | 4 ++-- netwerk/protocol/http/nsHttpHandler.cpp | 14 +++++++------- rdf/base/nsRDFService.cpp | 10 ++++++---- toolkit/components/commandlines/nsCommandLine.cpp | 4 ++-- xpcom/components/nsComponentManager.cpp | 6 +++--- xpcom/io/nsDirectoryService.cpp | 4 ++-- 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index 8981e8c4a30f..122d8c3a176b 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -1353,11 +1353,11 @@ nsIOService::PrefsChanged(nsIPrefBranch *prefs, const char *pref) void nsIOService::ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove) { - nsXPIDLCString portList; + nsCString portList; // Get a pref string and chop it up into a list of ports. prefBranch->GetCharPref(pref, getter_Copies(portList)); - if (portList) { + if (!portList.IsVoid()) { nsTArray portListArray; ParseString(portList, ',', portListArray); uint32_t index; diff --git a/netwerk/cache2/CacheEntry.cpp b/netwerk/cache2/CacheEntry.cpp index dd6d6bb5d481..db6daee1d538 100644 --- a/netwerk/cache2/CacheEntry.cpp +++ b/netwerk/cache2/CacheEntry.cpp @@ -1333,14 +1333,14 @@ NS_IMETHODIMP CacheEntry::GetSecurityInfo(nsISupports * *aSecurityInfo) NS_ENSURE_SUCCESS(mFileStatus, NS_ERROR_NOT_AVAILABLE); - nsXPIDLCString info; + nsCString info; nsCOMPtr secInfo; nsresult rv; rv = mFile->GetElement("security-info", getter_Copies(info)); NS_ENSURE_SUCCESS(rv, rv); - if (info) { + if (!info.IsVoid()) { rv = NS_DeserializeObject(info, getter_AddRefs(secInfo)); NS_ENSURE_SUCCESS(rv, rv); } diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index c2fad92edd01..580af12ffc0f 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -1322,12 +1322,12 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) } if (PREF_CHANGED(HTTP_PREF("version"))) { - nsXPIDLCString httpVersion; + nsCString httpVersion; prefs->GetCharPref(HTTP_PREF("version"), getter_Copies(httpVersion)); - if (httpVersion) { - if (!PL_strcmp(httpVersion, "1.1")) + if (!httpVersion.IsVoid()) { + if (httpVersion.EqualsLiteral("1.1")) mHttpVersion = NS_HTTP_VERSION_1_1; - else if (!PL_strcmp(httpVersion, "0.9")) + else if (httpVersion.EqualsLiteral("0.9")) mHttpVersion = NS_HTTP_VERSION_0_9; else mHttpVersion = NS_HTTP_VERSION_1_0; @@ -1335,10 +1335,10 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) } if (PREF_CHANGED(HTTP_PREF("proxy.version"))) { - nsXPIDLCString httpVersion; + nsCString httpVersion; prefs->GetCharPref(HTTP_PREF("proxy.version"), getter_Copies(httpVersion)); - if (httpVersion) { - if (!PL_strcmp(httpVersion, "1.1")) + if (!httpVersion.IsVoid()) { + if (httpVersion.EqualsLiteral("1.1")) mProxyHttpVersion = NS_HTTP_VERSION_1_1; else mProxyHttpVersion = NS_HTTP_VERSION_1_0; diff --git a/rdf/base/nsRDFService.cpp b/rdf/base/nsRDFService.cpp index 2d22adb2729c..6146f11f9496 100644 --- a/rdf/base/nsRDFService.cpp +++ b/rdf/base/nsRDFService.cpp @@ -1226,16 +1226,18 @@ RDFServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource) nsresult rv; - nsXPIDLCString uri; + nsCString uri; rv = aDataSource->GetURI(getter_Copies(uri)); if (NS_FAILED(rv)) return rv; //NS_ASSERTION(uri != nullptr, "datasource has no URI"); - if (! uri) + if (uri.IsVoid()) return NS_ERROR_UNEXPECTED; PLHashEntry** hep = - PL_HashTableRawLookup(mNamedDataSources, (*mNamedDataSources->keyHash)(uri), uri); + PL_HashTableRawLookup(mNamedDataSources, + (*mNamedDataSources->keyHash)(uri.get()), + uri.get()); // It may well be that this datasource was never registered. If // so, don't unregister it. @@ -1248,7 +1250,7 @@ RDFServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource) MOZ_LOG(gLog, LogLevel::Debug, ("rdfserv unregister-datasource [%p] %s", - aDataSource, (const char*) uri)); + aDataSource, uri.get())); return NS_OK; } diff --git a/toolkit/components/commandlines/nsCommandLine.cpp b/toolkit/components/commandlines/nsCommandLine.cpp index 5d591888932f..da014bc7b522 100644 --- a/toolkit/components/commandlines/nsCommandLine.cpp +++ b/toolkit/components/commandlines/nsCommandLine.cpp @@ -565,11 +565,11 @@ nsCommandLine::EnumerateValidators(EnumerateValidatorsCallback aCallback, void * while (NS_SUCCEEDED(strenum->HasMore(&hasMore)) && hasMore) { strenum->GetNext(entry); - nsXPIDLCString contractID; + nsCString contractID; rv = catman->GetCategoryEntry("command-line-validator", entry.get(), getter_Copies(contractID)); - if (!contractID) + if (contractID.IsVoid()) continue; nsCOMPtr clv(do_GetService(contractID.get())); diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 48d254558683..c48cdb5da388 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -93,7 +93,7 @@ nsGetServiceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const { nsresult rv; - nsXPIDLCString value; + nsCString value; nsCOMPtr catman; nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager; if (!compMgr) { @@ -120,12 +120,12 @@ nsGetServiceFromCategory::operator()(const nsIID& aIID, if (NS_FAILED(rv)) { goto error; } - if (!value) { + if (value.IsVoid()) { rv = NS_ERROR_SERVICE_NOT_AVAILABLE; goto error; } - rv = compMgr->nsComponentManagerImpl::GetServiceByContractID(value, + rv = compMgr->nsComponentManagerImpl::GetServiceByContractID(value.get(), aIID, aInstancePtr); if (NS_FAILED(rv)) { diff --git a/xpcom/io/nsDirectoryService.cpp b/xpcom/io/nsDirectoryService.cpp index 5643bf213af8..05e0d07bb547 100644 --- a/xpcom/io/nsDirectoryService.cpp +++ b/xpcom/io/nsDirectoryService.cpp @@ -463,11 +463,11 @@ nsDirectoryService::RegisterCategoryProviders() nsAutoCString entry; strings->GetNext(entry); - nsXPIDLCString contractID; + nsCString contractID; catman->GetCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY, entry.get(), getter_Copies(contractID)); - if (contractID) { + if (!contractID.IsVoid()) { nsCOMPtr provider = do_GetService(contractID.get()); if (provider) { RegisterProvider(provider);