Bug 1497972 - Use LookupForAdd in ImageLoader::LoadImage. r=mats
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 10 Oct 2018 19:09:59 +0000
changeset 496339 ad50275695e8d42a36e5f3151be4ee955a5185c2
parent 496338 9752f179b9c3007eca80f96585dcfd3d951ae222
child 496340 bea77a4e96999378c7c8dc1dbc90bbc585171ca9
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1497972
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 1497972 - Use LookupForAdd in ImageLoader::LoadImage. r=mats I think it's not really that awkward :) Differential Revision: https://phabricator.services.mozilla.com/D8268
layout/style/ImageLoader.cpp
--- a/layout/style/ImageLoader.cpp
+++ b/layout/style/ImageLoader.cpp
@@ -463,24 +463,27 @@ ImageLoader::LoadImage(nsIURI* aURI,
   MOZ_ASSERT(aImage);
   MOZ_ASSERT(aImage->LoadID() != 0);
 
   if (aImage->LoadID() == 0) {
     MOZ_ASSERT_UNREACHABLE("Image should have a valid LoadID");
     return;
   }
 
-  if (sImages->Contains(aImage->LoadID())) {
-    // This css::URLValue has already been loaded.
-    return;
+  ImageTableEntry* entry;
+
+  {
+    auto lookup = sImages->LookupForAdd(aImage->LoadID());
+    if (lookup) {
+      // This css::URLValue has already been loaded.
+      return;
+    }
+    entry = lookup.OrInsert([]() { return new ImageTableEntry(); });
   }
 
-  ImageTableEntry* entry = new ImageTableEntry();
-  sImages->Put(aImage->LoadID(), entry);
-
   if (!aURI) {
     return;
   }
 
   int32_t loadFlags = nsIRequest::LOAD_NORMAL |
                       nsContentUtils::CORSModeToLoadImageFlags(aCorsMode);
 
   RefPtr<imgRequestProxy> request;