Bug 1278925 - micro-optimize nsCOMArray appending with already_AddRefed AppendElement; r=erahm
authorNathan Froyd <froydnj@gmail.com>
Mon, 20 Jun 2016 18:38:10 -0400
changeset 302098 8623823c103f0dfe35a4094f6e6752e65633deb8
parent 302097 d4f903cba94d921ccf99931961d823f53389399c
child 302099 ac276f95b75118731e3ef913f2786858e7c7d206
push id78589
push usernfroyd@mozilla.com
push dateMon, 20 Jun 2016 14:39:30 +0000
treeherdermozilla-inbound@8623823c103f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1278925
milestone50.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 1278925 - micro-optimize nsCOMArray appending with already_AddRefed AppendElement; r=erahm In all of the places touched by this patch, the smart pointer we're appending is about to become unused, so simply .forget()'ing its reference into the appropriate nsCOMArray works just fine.
docshell/shistory/nsSHistory.cpp
dom/base/nsScriptLoader.cpp
dom/events/EventListenerManager.cpp
dom/plugins/base/nsPluginHost.cpp
layout/base/nsRefreshDriver.cpp
layout/inspector/inDOMView.cpp
toolkit/components/places/nsNavHistory.cpp
xpcom/glue/nsCategoryCache.h
--- a/docshell/shistory/nsSHistory.cpp
+++ b/docshell/shistory/nsSHistory.cpp
@@ -1691,17 +1691,17 @@ nsSHistory::CompareFrames(nsISHEntry* aP
 
   // Create an array for child docshells.
   nsCOMArray<nsIDocShell> docshells;
   for (int32_t i = 0; i < dsCount; ++i) {
     nsCOMPtr<nsIDocShellTreeItem> treeItem;
     aParent->GetChildAt(i, getter_AddRefs(treeItem));
     nsCOMPtr<nsIDocShell> shell = do_QueryInterface(treeItem);
     if (shell) {
-      docshells.AppendObject(shell);
+      docshells.AppendElement(shell.forget());
     }
   }
 
   // Search for something to load next.
   for (int32_t i = 0; i < ncnt; ++i) {
     // First get an entry which may cause a new page to be loaded.
     nsCOMPtr<nsISHEntry> nChild;
     nextContainer->GetChildAt(i, getter_AddRefs(nChild));
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -893,17 +893,17 @@ ResolveRequestedModules(nsModuleLoadRequ
       HandleResolveFailure(cx, ms, specifier);
       return NS_ERROR_FAILURE;
     }
 
     bool isAncestor;
     nsresult rv = RequestedModuleIsInAncestorList(aRequest, uri, &isAncestor);
     NS_ENSURE_SUCCESS(rv, rv);
     if (!isAncestor) {
-      aUrls.AppendElement(uri);
+      aUrls.AppendElement(uri.forget());
     }
   }
 
   return NS_OK;
 }
 
 void
 nsScriptLoader::StartFetchingModuleDependencies(nsModuleLoadRequest* aRequest)
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1554,17 +1554,17 @@ EventListenerManager::GetListenerInfo(ns
     }
     // EventListenerInfo is defined in XPCOM, so we have to go ahead
     // and convert to an XPCOM callback here...
     RefPtr<EventListenerInfo> info =
       new EventListenerInfo(eventType, listener.mListener.ToXPCOMCallback(),
                             listener.mFlags.mCapture,
                             listener.mFlags.mAllowUntrustedEvents,
                             listener.mFlags.mInSystemGroup);
-    aList->AppendObject(info);
+    aList->AppendElement(info.forget());
   }
   return NS_OK;
 }
 
 bool
 EventListenerManager::HasUnloadListeners()
 {
   uint32_t count = mListeners.Length();
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -2011,17 +2011,17 @@ GetExtensionDirectories(nsCOMArray<nsIFi
   while (NS_SUCCEEDED(list->HasMoreElements(&more)) && more) {
     nsCOMPtr<nsISupports> next;
     if (NS_FAILED(list->GetNext(getter_AddRefs(next)))) {
       break;
     }
     nsCOMPtr<nsIFile> file = do_QueryInterface(next);
     if (file) {
       file->Normalize();
-      dirs.AppendElement(file);
+      dirs.AppendElement(file.forget());
     }
   }
 }
 
 struct CompareFilesByTime
 {
   bool
   LessThan(const nsCOMPtr<nsIFile>& a, const nsCOMPtr<nsIFile>& b) const
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -1871,17 +1871,17 @@ nsRefreshDriver::Tick(int64_t aNowEpoch,
     nsCOMArray<imgIContainer> imagesToRefresh(mRequests.Count());
 
     for (auto iter = mRequests.Iter(); !iter.Done(); iter.Next()) {
       nsISupportsHashKey* entry = iter.Get();
       auto req = static_cast<imgIRequest*>(entry->GetKey());
       MOZ_ASSERT(req, "Unable to retrieve the image request");
       nsCOMPtr<imgIContainer> image;
       if (NS_SUCCEEDED(req->GetImage(getter_AddRefs(image)))) {
-        imagesToRefresh.AppendElement(image);
+        imagesToRefresh.AppendElement(image.forget());
       }
     }
 
     for (uint32_t i = 0; i < imagesToRefresh.Length(); i++) {
       imagesToRefresh[i]->RequestRefresh(aNowTime);
     }
   }
 
--- a/layout/inspector/inDOMView.cpp
+++ b/layout/inspector/inDOMView.cpp
@@ -1257,28 +1257,28 @@ inDOMView::AppendKidsToArray(nsIDOMNodeL
         NS_ASSERTION(data, "Does not implement nsIDOMCharacterData!");
         bool ignore;
         mDOMUtils->IsIgnorableWhitespace(data, &ignore);
         if (ignore) {
           continue;
         }
       }
 
-      aArray.AppendObject(kid);
+      aArray.AppendElement(kid.forget());
     }
   }
 
   return NS_OK;
 }
 
 nsresult
 inDOMView::AppendAttrsToArray(nsIDOMMozNamedAttrMap* aAttributes,
                               nsCOMArray<nsIDOMNode>& aArray)
 {
   uint32_t l = 0;
   aAttributes->GetLength(&l);
   nsCOMPtr<nsIDOMAttr> attribute;
   for (uint32_t i = 0; i < l; ++i) {
     aAttributes->Item(i, getter_AddRefs(attribute));
-    aArray.AppendObject(attribute);
+    aArray.AppendElement(attribute.forget());
   }
   return NS_OK;
 }
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -1231,17 +1231,17 @@ nsNavHistory::ExecuteQueries(nsINavHisto
   nsCOMPtr<nsNavHistoryQueryOptions> options = do_QueryInterface(aOptions);
   NS_ENSURE_TRUE(options, NS_ERROR_INVALID_ARG);
 
   // concrete queries array
   nsCOMArray<nsNavHistoryQuery> queries;
   for (uint32_t i = 0; i < aQueryCount; i ++) {
     nsCOMPtr<nsNavHistoryQuery> query = do_QueryInterface(aQueries[i], &rv);
     NS_ENSURE_SUCCESS(rv, rv);
-    queries.AppendObject(query);
+    queries.AppendElement(query.forget());
   }
 
   // Create the root node.
   RefPtr<nsNavHistoryContainerResultNode> rootNode;
   int64_t folderId = GetSimpleBookmarksQueryFolder(queries, options);
   if (folderId) {
     // In the simple case where we're just querying children of a single
     // bookmark folder, we can more efficiently generate results.
@@ -2460,17 +2460,17 @@ nsNavHistory::CleanupPlacesOnVisitsDelet
     nsCOMPtr<nsIURI> uri;
     rv = NS_NewURI(getter_AddRefs(uri), URLString);
     NS_ENSURE_SUCCESS(rv, rv);
     if (wholeEntry) {
       if (!filteredPlaceIds.IsEmpty()) {
         filteredPlaceIds.Append(',');
       }
       filteredPlaceIds.AppendInt(placeId);
-      URIs.AppendObject(uri);
+      URIs.AppendElement(uri.forget());
       GUIDs.AppendElement(guid);
     }
     else {
       // Notify that we will delete all visits for this page, but not the page
       // itself, since it's bookmarked or a place: query.
       NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
                        nsINavHistoryObserver,
                        OnDeleteVisits(uri, 0, guid, nsINavHistoryObserver::REASON_DELETED, 0));
@@ -2998,17 +2998,17 @@ nsNavHistory::AsyncExecuteLegacyQueries(
   NS_ENSURE_ARG(aOptions);
   NS_ENSURE_ARG(aCallback);
   NS_ENSURE_ARG_POINTER(_stmt);
 
   nsCOMArray<nsNavHistoryQuery> queries;
   for (uint32_t i = 0; i < aQueryCount; i ++) {
     nsCOMPtr<nsNavHistoryQuery> query = do_QueryInterface(aQueries[i]);
     NS_ENSURE_STATE(query);
-    queries.AppendObject(query);
+    queries.AppendElement(query.forget());
   }
   NS_ENSURE_ARG_MIN(queries.Count(), 1);
 
   nsCOMPtr<nsNavHistoryQueryOptions> options = do_QueryInterface(aOptions);
   NS_ENSURE_ARG(options);
 
   nsCString queryString;
   bool paramsPresent = false;
@@ -3612,17 +3612,17 @@ nsNavHistory::ResultsAsList(mozIStorageS
   nsCOMPtr<mozIStorageValueArray> row = do_QueryInterface(statement, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMore = false;
   while (NS_SUCCEEDED(statement->ExecuteStep(&hasMore)) && hasMore) {
     RefPtr<nsNavHistoryResultNode> result;
     rv = RowToResult(row, aOptions, getter_AddRefs(result));
     NS_ENSURE_SUCCESS(rv, rv);
-    aResults->AppendObject(result);
+    aResults->AppendElement(result.forget());
   }
   return NS_OK;
 }
 
 const int64_t UNDEFINED_URN_VALUE = -1;
 
 // Create a urn (like
 // urn:places-persist:place:group=0&group=1&sort=1&type=1,,%28local%20files%29)
--- a/xpcom/glue/nsCategoryCache.h
+++ b/xpcom/glue/nsCategoryCache.h
@@ -74,17 +74,17 @@ public:
     if (!mObserver) {
       mObserver = new nsCategoryObserver(mCategoryName.get());
     }
 
     for (auto iter = mObserver->GetHash().Iter(); !iter.Done(); iter.Next()) {
       nsISupports* entry = iter.UserData();
       nsCOMPtr<T> service = do_QueryInterface(entry);
       if (service) {
-        aResult.AppendObject(service);
+        aResult.AppendElement(service.forget());
       }
     }
   }
 
 private:
   // Not to be implemented
   nsCategoryCache(const nsCategoryCache<T>&);