Bug 1367207 part 4 - Use LookupRemoveIf() to avoid a second hashtable lookup for Remove(). r=dholbert
authorMats Palmgren <mats@mozilla.com>
Wed, 07 Jun 2017 15:22:41 +0200
changeset 413169 7fc0cbe0d71cfd101e6e9f536c28b7f7830c4e5b
parent 413168 7307d037a9227f8441674713dd754ac893d243d8
child 413170 5c7be210a5c7298984a3a073a9edeac9370362df
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1367207
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 1367207 part 4 - Use LookupRemoveIf() to avoid a second hashtable lookup for Remove(). r=dholbert MozReview-Commit-ID: 6EYkiKpLHvI
layout/style/ImageLoader.cpp
--- a/layout/style/ImageLoader.cpp
+++ b/layout/style/ImageLoader.cpp
@@ -142,45 +142,45 @@ ImageLoader::RemoveRequestToFrameMapping
 #ifdef DEBUG
   {
     nsCOMPtr<imgINotificationObserver> observer;
     aRequest->GetNotificationObserver(getter_AddRefs(observer));
     MOZ_ASSERT(!observer || observer == this);
   }
 #endif
 
-  FrameSet* frameSet = nullptr;
-  mRequestToFrameMap.Get(aRequest, &frameSet);
-  if (frameSet) {
-    frameSet->RemoveElementSorted(aFrame);
-    if (frameSet->IsEmpty()) {
-      mRequestToFrameMap.Remove(aRequest);
-
-      nsPresContext* presContext = GetPresContext();
-      if (presContext) {
-        nsLayoutUtils::DeregisterImageRequest(presContext, aRequest, nullptr);
+  mRequestToFrameMap.LookupRemoveIf(aRequest,
+    [aRequest, aFrame, this] (FrameSet* aFrameSet) {
+      MOZ_ASSERT(aFrameSet, "This should never be null");
+      aFrameSet->RemoveElementSorted(aFrame);
+      bool remove = aFrameSet->IsEmpty();
+      if (remove) {
+        nsPresContext* presContext = GetPresContext();
+        if (presContext) {
+          nsLayoutUtils::DeregisterImageRequest(presContext, aRequest, nullptr);
+        }
       }
-    }
-  }
+      return remove;
+    });
 }
 
 void
 ImageLoader::RemoveFrameToRequestMapping(imgIRequest* aRequest,
                                          nsIFrame*    aFrame)
 {
-  RequestSet* requestSet = nullptr;
-  mFrameToRequestMap.Get(aFrame, &requestSet);
-  if (requestSet) {
-    MOZ_ASSERT(aFrame->HasImageRequest(), "HasImageRequest is lying");
-    requestSet->RemoveElementSorted(aRequest);
-    if (requestSet->IsEmpty()) {
-      mFrameToRequestMap.Remove(aFrame);
-      aFrame->SetHasImageRequest(false);
-    }
-  }
+  mFrameToRequestMap.LookupRemoveIf(aFrame,
+    [aRequest, aFrame] (RequestSet* aRequestSet) {
+      MOZ_ASSERT(aRequestSet, "This should never be null");
+      aRequestSet->RemoveElementSorted(aRequest);
+      bool remove = aRequestSet->IsEmpty();
+      if (remove) {
+        aFrame->SetHasImageRequest(false);
+      }
+      return remove;
+    });
 }
 
 void
 ImageLoader::DisassociateRequestFromFrame(imgIRequest* aRequest,
                                           nsIFrame*    aFrame)
 {
   MOZ_ASSERT(aFrame->HasImageRequest(), "why call me?");
   RemoveRequestToFrameMapping(aRequest, aFrame);