Bug 1497972 - Use LookupForAdd in ImageLoader::LoadImage. r=mats
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 10 Oct 2018 19:09:59 +0000
changeset 440603 ad50275695e8d42a36e5f3151be4ee955a5185c2
parent 440602 9752f179b9c3007eca80f96585dcfd3d951ae222
child 440604 bea77a4e96999378c7c8dc1dbc90bbc585171ca9
push id34827
push usertoros@mozilla.com
push dateThu, 11 Oct 2018 03:53:09 +0000
treeherdermozilla-central@b89a744deccb [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;