Bug 1186780: Replace EnumerateRead with new iterators in ImageLoader. r=dbaron
authorKyle Huey <khuey@kylehuey.com>
Thu, 30 Jul 2015 13:48:10 -0700
changeset 288878 43ae47ffe011363092fd4a5d64c14d8a7c9ce69e
parent 288877 d8e044ff83721b62f5bf408840cc7e14edf7cfeb
child 288879 e9012f07826574b0b3859ab88f765e7e19fdc587
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1186780
milestone42.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 1186780: Replace EnumerateRead with new iterators in ImageLoader. r=dbaron
layout/style/ImageLoader.cpp
layout/style/ImageLoader.h
--- a/layout/style/ImageLoader.cpp
+++ b/layout/style/ImageLoader.cpp
@@ -13,43 +13,16 @@
 #include "nsDisplayList.h"
 #include "FrameLayerBuilder.h"
 #include "nsSVGEffects.h"
 #include "imgIContainer.h"
 
 namespace mozilla {
 namespace css {
 
-/* static */ PLDHashOperator
-ImageLoader::SetAnimationModeEnumerator(nsISupports* aKey, FrameSet* aValue,
-                                        void* aClosure)
-{
-  imgIRequest* request = static_cast<imgIRequest*>(aKey);
-
-  uint16_t* mode = static_cast<uint16_t*>(aClosure);
-
-#ifdef DEBUG
-  {
-    nsCOMPtr<imgIRequest> debugRequest = do_QueryInterface(aKey);
-    NS_ASSERTION(debugRequest == request, "This is bad");
-  }
-#endif
-
-  nsCOMPtr<imgIContainer> container;
-  request->GetImage(getter_AddRefs(container));
-  if (!container) {
-    return PL_DHASH_NEXT;
-  }
-
-  // This can fail if the image is in error, and we don't care.
-  container->SetAnimationMode(*mode);
-
-  return PL_DHASH_NEXT;
-}
-
 void
 ImageLoader::DropDocumentReference()
 {
   // It's okay if GetPresContext returns null here (due to the presshell pointer
   // on the document being null) as that means the presshell has already
   // been destroyed, and it also calls ClearFrames when it is destroyed.
   ClearFrames(GetPresContext());
 
@@ -221,46 +194,57 @@ ImageLoader::DropRequestsForFrame(nsIFra
 void
 ImageLoader::SetAnimationMode(uint16_t aMode)
 {
   NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode ||
                aMode == imgIContainer::kDontAnimMode ||
                aMode == imgIContainer::kLoopOnceAnimMode,
                "Wrong Animation Mode is being set!");
 
-  mRequestToFrameMap.EnumerateRead(SetAnimationModeEnumerator, &aMode);
-}
-
-/* static */ PLDHashOperator
-ImageLoader::DeregisterRequestEnumerator(nsISupports* aKey, FrameSet* aValue,
-                                         void* aClosure)
-{
-  imgIRequest* request = static_cast<imgIRequest*>(aKey);
+  for (auto iter = mRequestToFrameMap.ConstIter(); !iter.Done(); iter.Next()) {
+    auto request = static_cast<imgIRequest*>(iter.Key());
 
 #ifdef DEBUG
-  {
-    nsCOMPtr<imgIRequest> debugRequest = do_QueryInterface(aKey);
-    NS_ASSERTION(debugRequest == request, "This is bad");
-  }
+    {
+      nsCOMPtr<imgIRequest> debugRequest = do_QueryInterface(key);
+      NS_ASSERTION(debugRequest == request, "This is bad");
+    }
 #endif
 
-  nsPresContext* presContext = static_cast<nsPresContext*>(aClosure);
-  if (presContext) {
-    nsLayoutUtils::DeregisterImageRequest(presContext,
-                                          request,
-                                          nullptr);
+    nsCOMPtr<imgIContainer> container;
+    request->GetImage(getter_AddRefs(container));
+    if (!container) {
+      continue;
+    }
+
+    // This can fail if the image is in error, and we don't care.
+    container->SetAnimationMode(aMode);
   }
-
-  return PL_DHASH_NEXT;
 }
 
 void
 ImageLoader::ClearFrames(nsPresContext* aPresContext)
 {
-  mRequestToFrameMap.EnumerateRead(DeregisterRequestEnumerator, aPresContext);
+  for (auto iter = mRequestToFrameMap.ConstIter(); !iter.Done(); iter.Next()) {
+    auto request = static_cast<imgIRequest*>(iter.Key());
+
+#ifdef DEBUG
+    {
+      nsCOMPtr<imgIRequest> debugRequest = do_QueryInterface(key);
+      NS_ASSERTION(debugRequest == request, "This is bad");
+    }
+#endif
+
+    if (aPresContext) {
+      nsLayoutUtils::DeregisterImageRequest(aPresContext,
+					    request,
+					    nullptr);
+    }
+  }
+
   mRequestToFrameMap.Clear();
   mFrameToRequestMap.Clear();
 }
 
 void
 ImageLoader::LoadImage(nsIURI* aURI, nsIPrincipal* aOriginPrincipal,
                        nsIURI* aReferrer, ImageLoader::Image* aImage)
 {
--- a/layout/style/ImageLoader.h
+++ b/layout/style/ImageLoader.h
@@ -88,24 +88,16 @@ private:
 
   void AddImage(Image* aCSSImage);
   void RemoveImage(Image* aCSSImage);
 
   nsPresContext* GetPresContext();
 
   void DoRedraw(FrameSet* aFrameSet, bool aForcePaint);
 
-  static PLDHashOperator
-  SetAnimationModeEnumerator(nsISupports* aKey, FrameSet* aValue,
-                             void* aClosure);
-
-  static PLDHashOperator
-  DeregisterRequestEnumerator(nsISupports* aKey, FrameSet* aValue,
-                              void* aClosure);
-
   nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
   nsresult OnFrameComplete(imgIRequest* aRequest);
   nsresult OnImageIsAnimated(imgIRequest* aRequest);
   nsresult OnFrameUpdate(imgIRequest* aRequest);
 
   // A map of imgIRequests to the nsIFrames that are using them.
   RequestToFrameMap mRequestToFrameMap;