Bug 1494127 - Fix trivial calls to do_QueryInterface that return an nsresult r=smaug
authorAndrew McCreight <continuation@gmail.com>
Mon, 01 Oct 2018 21:38:43 +0000
changeset 439205 07184f24860bafda10d0eac583236ae2e4544fef
parent 439204 995cd5fca351d5bf3c00e745f3cc22a2fab6fd72
child 439206 de5c2979877f9f7fb8731a86ad52aacf0c5f1082
push id34758
push userdvarga@mozilla.com
push dateTue, 02 Oct 2018 21:45:21 +0000
treeherdermozilla-central@4392b5198fb7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1494127
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494127 - Fix trivial calls to do_QueryInterface that return an nsresult r=smaug Calls to do_QueryInterface to a base class can be replaced by a static cast, which is faster. Differential Revision: https://phabricator.services.mozilla.com/D7224
extensions/permissions/nsContentBlocker.cpp
image/decoders/icon/nsIconURI.cpp
js/xpconnect/src/XPCShellImpl.cpp
modules/libjar/zipwriter/nsZipDataStream.cpp
netwerk/base/nsStreamListenerTee.cpp
netwerk/cache/nsCacheService.cpp
netwerk/streamconv/converters/nsMultiMixedConv.cpp
netwerk/streamconv/nsStreamConverterService.cpp
toolkit/components/find/nsWebBrowserFind.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
toolkit/xre/nsUpdateDriver.cpp
widget/nsBaseFilePicker.cpp
--- a/extensions/permissions/nsContentBlocker.cpp
+++ b/extensions/permissions/nsContentBlocker.cpp
@@ -118,18 +118,17 @@ nsContentBlocker::Init()
     prefBranch->SetIntPref("image", newPref);
     oldPrefBranch->ClearUserPref("network.image.imageBehavior");
   }
 
 
   // The branch is not a copy of the prefservice, but a new object, because
   // it is a non-default branch. Adding obeservers to it will only work if
   // we make sure that the object doesn't die. So, keep a reference to it.
-  mPrefBranchInternal = do_QueryInterface(prefBranch, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  mPrefBranchInternal = prefBranch;
 
   rv = mPrefBranchInternal->AddObserver("", this, true);
   PrefChanged(prefBranch, nullptr);
 
   return rv;
 }
 
 #undef  LIMIT
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -507,23 +507,19 @@ nsMozIconURI::SchemeIs(const char* aSche
 
   *aEquals = PL_strcasecmp("moz-icon", aScheme) ? false : true;
   return NS_OK;
 }
 
 nsresult
 nsMozIconURI::Clone(nsIURI** result)
 {
-  nsresult rv;
   nsCOMPtr<nsIURL> newIconURL;
   if (mIconURL) {
-    newIconURL = do_QueryInterface(mIconURL, &rv);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
+    newIconURL = mIconURL;
   }
 
   RefPtr<nsMozIconURI> uri = new nsMozIconURI();
   newIconURL.swap(uri->mIconURL);
   uri->mSize = mSize;
   uri->mContentType = mContentType;
   uri->mFileName = mFileName;
   uri->mStockIcon = mStockIcon;
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1219,17 +1219,17 @@ XRE_XPCShellMain(int argc, char** argv, 
         if (argc > 1 && !strcmp(argv[1], "-a")) {
             if (argc < 3) {
                 return usage();
             }
 
             nsCOMPtr<nsIFile> dir;
             rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(dir));
             if (NS_SUCCEEDED(rv)) {
-                appDir = do_QueryInterface(dir, &rv);
+                appDir = dir;
                 dirprovider.SetAppDir(appDir);
             }
             if (NS_FAILED(rv)) {
                 printf("Couldn't use given appdir.\n");
                 return 1;
             }
             argc -= 2;
             argv += 2;
--- a/modules/libjar/zipwriter/nsZipDataStream.cpp
+++ b/modules/libjar/zipwriter/nsZipDataStream.cpp
@@ -46,18 +46,17 @@ nsresult nsZipDataStream::Init(nsZipWrit
         nsCOMPtr<nsIStreamConverter> converter =
                               new nsDeflateConverter(aCompression);
         NS_ENSURE_TRUE(converter, NS_ERROR_OUT_OF_MEMORY);
 
         rv = converter->AsyncConvertData("uncompressed", "rawdeflate", mOutput,
                                          nullptr);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        mOutput = do_QueryInterface(converter, &rv);
-        NS_ENSURE_SUCCESS(rv, rv);
+        mOutput = converter;
     }
     else {
         mHeader->mMethod = ZIP_METHOD_STORE;
     }
 
     return NS_OK;
 }
 
--- a/netwerk/base/nsStreamListenerTee.cpp
+++ b/netwerk/base/nsStreamListenerTee.cpp
@@ -80,18 +80,17 @@ nsStreamListenerTee::OnDataAvailable(nsI
         mInputTee = do_QueryInterface(tee, &rv);
         if (NS_FAILED(rv)) return rv;
     }
     else {
         // re-initialize the input tee since the input stream may have changed.
         rv = mInputTee->SetSource(input);
         if (NS_FAILED(rv)) return rv;
 
-        tee = do_QueryInterface(mInputTee, &rv);
-        if (NS_FAILED(rv)) return rv;
+        tee = mInputTee;
     }
 
     return mListener->OnDataAvailable(request, context, tee, offset, count);
 }
 
 NS_IMETHODIMP
 nsStreamListenerTee::CheckListenerChain()
 {
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -741,18 +741,19 @@ nsCacheProfilePrefObserver::ReadPrefs(ns
                                                       "Cache");
             }
         }
         // use file cache in build tree only if asked, to avoid cache dir litter
         if (!directory && PR_GetEnv("NECKO_DEV_ENABLE_DISK_CACHE")) {
             rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
                                         getter_AddRefs(directory));
         }
-        if (directory)
-            mDiskCacheParentDirectory = do_QueryInterface(directory, &rv);
+        if (directory) {
+            mDiskCacheParentDirectory = directory;
+        }
     }
     if (mDiskCacheParentDirectory) {
         bool firstSmartSizeRun;
         rv = branch->GetBoolPref(DISK_CACHE_SMART_SIZE_FIRST_RUN_PREF,
                                  &firstSmartSizeRun);
         if (NS_FAILED(rv))
             firstSmartSizeRun = false;
         if (PermittedToSmartSize(branch, firstSmartSizeRun)) {
@@ -811,18 +812,19 @@ nsCacheProfilePrefObserver::ReadPrefs(ns
         }
 #if DEBUG
         if (!directory) {
             // use current process directory during development
             rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
                                         getter_AddRefs(directory));
         }
 #endif
-        if (directory)
-            mOfflineCacheParentDirectory = do_QueryInterface(directory, &rv);
+        if (directory) {
+            mOfflineCacheParentDirectory = directory;
+        }
     }
 
     // read memory cache device prefs
     (void) branch->GetBoolPref(MEMORY_CACHE_ENABLE_PREF, &mMemoryCacheEnabled);
 
     mMemoryCacheCapacity = -1;
     (void) branch->GetIntPref(MEMORY_CACHE_CAPACITY_PREF,
                               &mMemoryCacheCapacity);
--- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp
@@ -991,20 +991,17 @@ nsMultiMixedConv::SendData()
     if (NS_FAILED(rv))
         return rv;
 
     rv = ss->ShareData(rawData, mRawDataLength);
     mRawData = nullptr;
     if (NS_FAILED(rv))
         return rv;
 
-    nsCOMPtr<nsIInputStream> inStream(do_QueryInterface(ss, &rv));
-    if (NS_FAILED(rv)) return rv;
-
-    return mPartChannel->SendOnDataAvailable(mContext, inStream, offset, mRawDataLength);
+    return mPartChannel->SendOnDataAvailable(mContext, ss, offset, mRawDataLength);
 }
 
 void
 nsMultiMixedConv::HeadersToDefault()
 {
     mContentLength = UINT64_MAX;
     mContentType.Truncate();
     mContentDisposition.Truncate();
--- a/netwerk/streamconv/nsStreamConverterService.cpp
+++ b/netwerk/streamconv/nsStreamConverterService.cpp
@@ -494,28 +494,22 @@ nsStreamConverterService::AsyncConvertDa
 
             // connect the converter w/ the listener that should get the converted data.
             rv = converter->AsyncConvertData(fromStr.get(), toStr.get(), finalListener, aContext);
             if (NS_FAILED(rv)) {
                 delete converterChain;
                 return rv;
             }
 
-            nsCOMPtr<nsIStreamListener> chainListener(do_QueryInterface(converter, &rv));
-            if (NS_FAILED(rv)) {
-                delete converterChain;
-                return rv;
-            }
-
             // the last iteration of this loop will result in finalListener
             // pointing to the converter that "starts" the conversion chain.
             // this converter's "from" type is the original "from" type. Prior
             // to the last iteration, finalListener will continuously be wedged
             // into the next listener in the chain, then be updated.
-            finalListener = chainListener;
+            finalListener = converter;
         }
         delete converterChain;
         // return the first listener in the chain.
         finalListener.forget(_retval);
     } else {
         // we're going direct.
         rv = listener->AsyncConvertData(aFromType, aToType, aListener, aContext);
         listener.forget(_retval);
--- a/toolkit/components/find/nsWebBrowserFind.cpp
+++ b/toolkit/components/find/nsWebBrowserFind.cpp
@@ -134,21 +134,17 @@ nsWebBrowserFind::FindNext(bool* aResult
   rv = rootDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeAll,
                                            enumDirection,
                                            getter_AddRefs(docShellEnumerator));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // remember where we started
-  nsCOMPtr<nsIDocShellTreeItem> startingItem =
-    do_QueryInterface(searchFrame->GetDocShell(), &rv);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
+  nsCOMPtr<nsIDocShellTreeItem> startingItem = searchFrame->GetDocShell();
 
   nsCOMPtr<nsIDocShellTreeItem> curItem;
 
   // XXX We should avoid searching in frameset documents here.
   // We also need to honour mSearchSubFrames and mSearchParentFrames.
   bool hasMore, doFind = false;
   while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) &&
          hasMore) {
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -557,18 +557,17 @@ nsTypeAheadFind::FindItNow(nsIPresShell 
          * the element only if focus is in our content window, i.e.
          * |if (focusedWindow.top == ourWindow.top)| */
         bool shouldFocusEditableElement = false;
         if (fm) {
           nsCOMPtr<mozIDOMWindowProxy> focusedWindow;
           nsresult rv = fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
           if (NS_SUCCEEDED(rv) && focusedWindow) {
             auto* fwPI = nsPIDOMWindowOuter::From(focusedWindow);
-            nsCOMPtr<nsIDocShellTreeItem> fwTreeItem
-              (do_QueryInterface(fwPI->GetDocShell(), &rv));
+            nsCOMPtr<nsIDocShellTreeItem> fwTreeItem(fwPI->GetDocShell());
             if (NS_SUCCEEDED(rv)) {
               nsCOMPtr<nsIDocShellTreeItem> fwRootTreeItem;
               rv = fwTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(fwRootTreeItem));
               if (NS_SUCCEEDED(rv) && fwRootTreeItem == rootContentTreeItem)
                 shouldFocusEditableElement = true;
             }
           }
         }
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -170,18 +170,18 @@ GetFile(nsIFile* dir, const nsACString& 
   rv = dir->Clone(getter_AddRefs(file));
   if (NS_FAILED(rv))
     return false;
 
   rv = file->AppendNative(name);
   if (NS_FAILED(rv))
     return false;
 
-  result = do_QueryInterface(file, &rv);
-  return NS_SUCCEEDED(rv);
+  result = file;
+  return true;
 }
 
 static bool
 GetStatusFile(nsIFile *dir, nsCOMPtr<nsIFile> &result)
 {
   return GetFile(dir, NS_LITERAL_CSTRING("update.status"), result);
 }
 
--- a/widget/nsBaseFilePicker.cpp
+++ b/widget/nsBaseFilePicker.cpp
@@ -300,18 +300,18 @@ NS_IMETHODIMP nsBaseFilePicker::SetDispl
   if (!aDirectory) {
     mDisplayDirectory = nullptr;
     return NS_OK;
   }
   nsCOMPtr<nsIFile> directory;
   nsresult rv = aDirectory->Clone(getter_AddRefs(directory));
   if (NS_FAILED(rv))
     return rv;
-  mDisplayDirectory = do_QueryInterface(directory, &rv);
-  return rv;
+  mDisplayDirectory = directory;
+  return NS_OK;
 }
 
 // Get the display directory
 NS_IMETHODIMP nsBaseFilePicker::GetDisplayDirectory(nsIFile **aDirectory)
 {
   *aDirectory = nullptr;
 
   // if displaySpecialDirectory has been previously called, let's abort this