Bug 1370654 - Use mPendingLoads.GetOrInsert() to avoid a second hashtable lookup for Put(). Remove a redundant Get() before Remove(). r=froydnj
authorMats Palmgren <mats@mozilla.com>
Thu, 08 Jun 2017 12:48:32 +0200
changeset 411077 d1a431f894c29fe4ef5ebde3dc6431d1566307d2
parent 411076 ee20b7f985f5471b1a095f030505796ed97365b3
child 411078 97735d7197e2004195d3689e332af6efe968673d
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1370654
milestone55.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 1370654 - Use mPendingLoads.GetOrInsert() to avoid a second hashtable lookup for Put(). Remove a redundant Get() before Remove(). r=froydnj MozReview-Commit-ID: 36rxXpEwKcB
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -736,26 +736,25 @@ nsExternalResourceMap::RequestResource(n
   }
 
   ExternalResource* resource;
   mMap.Get(clone, &resource);
   if (resource) {
     return resource->mDocument;
   }
 
-  RefPtr<PendingLoad> load;
-  mPendingLoads.Get(clone, getter_AddRefs(load));
-  if (load) {
+  RefPtr<PendingLoad>& loadEntry = mPendingLoads.GetOrInsert(clone);
+  if (loadEntry) {
+    RefPtr<PendingLoad> load(loadEntry);
     load.forget(aPendingLoad);
     return nullptr;
   }
 
-  load = new PendingLoad(aDisplayDocument);
-
-  mPendingLoads.Put(clone, load);
+  RefPtr<PendingLoad> load(new PendingLoad(aDisplayDocument));
+  loadEntry = load;
 
   if (NS_FAILED(load->StartLoad(clone, aRequestingNode))) {
     // Make sure we don't thrash things by trying this load again, since
     // chances are it failed for good reasons (security check, etc).
     AddExternalResource(clone, nullptr, nullptr, aDisplayDocument);
   } else {
     load.forget(aPendingLoad);
   }
@@ -868,18 +867,17 @@ nsExternalResourceMap::AddExternalResour
                                            nsILoadGroup* aLoadGroup,
                                            nsIDocument* aDisplayDocument)
 {
   NS_PRECONDITION(aURI, "Unexpected call");
   NS_PRECONDITION((aViewer && aLoadGroup) || (!aViewer && !aLoadGroup),
                   "Must have both or neither");
 
   RefPtr<PendingLoad> load;
-  mPendingLoads.Get(aURI, getter_AddRefs(load));
-  mPendingLoads.Remove(aURI);
+  mPendingLoads.Remove(aURI, getter_AddRefs(load));
 
   nsresult rv = NS_OK;
 
   nsCOMPtr<nsIDocument> doc;
   if (aViewer) {
     doc = aViewer->GetDocument();
     NS_ASSERTION(doc, "Must have a document");