Backout dcdbaae3b40f (bug 1278688) r=me
authorBen Kelly <ben@wanderview.com>
Wed, 08 Jun 2016 12:03:31 -0700
changeset 301122 a5e6427b76956ffb5f879ab7f3f17bd9e4bb9ac7
parent 301121 1c0fc657e200d852dbb835027e652d0042858317
child 301123 8dc18bf5abac83c7adb2791eb582f1722a244666
push id78220
push userbkelly@mozilla.com
push dateWed, 08 Jun 2016 19:03:39 +0000
treeherdermozilla-inbound@a5e6427b7695 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1278688
milestone50.0a1
backs outdcdbaae3b40f20b2a9e13f049c4ed2cf81066e5c
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
Backout dcdbaae3b40f (bug 1278688) r=me
layout/style/Loader.cpp
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1117,19 +1117,21 @@ Loader::CreateSheet(nsIURI* aURI,
   if (aURI && GetStyleBackendType() == StyleBackendType::Gecko) {
     aSheetState = eSheetComplete;
     StyleSheetHandle::RefPtr sheet;
 
     // First, the XUL cache
 #ifdef MOZ_XUL
     if (IsChromeURI(aURI)) {
       nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
-      if (cache && cache->IsEnabled()) {
-        sheet = cache->GetStyleSheet(aURI);
-        LOG(("  From XUL cache: %p", sheet->AsVoidPtr()));
+      if (cache) {
+        if (cache->IsEnabled()) {
+          sheet = cache->GetStyleSheet(aURI);
+          LOG(("  From XUL cache: %p", sheet->AsVoidPtr()));
+        }
       }
     }
 #endif
 
     bool fromCompleteSheets = false;
     if (!sheet) {
       // Then our per-document complete sheets.
       URIPrincipalReferrerPolicyAndCORSModeHashKey key(aURI, aLoaderPrincipal, aCORSMode, aReferrerPolicy);
@@ -1217,41 +1219,24 @@ Loader::CreateSheet(nsIURI* aURI,
                    "Sheet thinks it's not complete while we think it is");
 
       RefPtr<CSSStyleSheet> clonedSheet =
         sheet->AsGecko()->Clone(nullptr, nullptr, nullptr, nullptr);
       *aSheet = Move(clonedSheet);
       if (*aSheet && fromCompleteSheets &&
           !sheet->AsGecko()->GetOwnerNode() &&
           !sheet->AsGecko()->GetParentSheet()) {
-
-#ifdef MOZ_XUL
-        if (IsChromeURI(aURI)) {
-          nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
-          if (cache && cache->IsEnabled()) {
-            // Always store our latest sheet in the cache so that old,
-            // unreferenced sheet objects can be freed.
-            LOG(("  Updating sheet in XUL prototype cache"));
-            NS_ASSERTION(clonedSheet->IsComplete(),
-                         "Should only be caching complete sheets");
-            cache->PutStyleSheet(clonedSheet);
-          }
-        } else {
-#endif
-          // The sheet we're cloning isn't actually referenced by
-          // anyone.  Replace it in the cache, so that if our CSSOM is
-          // later modified we don't end up with two copies of our inner
-          // hanging around.
-          URIPrincipalReferrerPolicyAndCORSModeHashKey key(aURI, aLoaderPrincipal, aCORSMode, aReferrerPolicy);
-          NS_ASSERTION((*aSheet)->AsGecko()->IsComplete(),
-                       "Should only be caching complete sheets");
-          mSheets->mCompleteSheets.Put(&key, *aSheet);
-#ifdef MOZ_XUL
-        }
-#endif
+        // The sheet we're cloning isn't actually referenced by
+        // anyone.  Replace it in the cache, so that if our CSSOM is
+        // later modified we don't end up with two copies of our inner
+        // hanging around.
+        URIPrincipalReferrerPolicyAndCORSModeHashKey key(aURI, aLoaderPrincipal, aCORSMode, aReferrerPolicy);
+        NS_ASSERTION((*aSheet)->AsGecko()->IsComplete(),
+                     "Should only be caching complete sheets");
+        mSheets->mCompleteSheets.Put(&key, *aSheet);
       }
     }
   }
 
   if (!*aSheet) {
     aSheetState = eSheetNeedsParser;
     nsIURI *sheetURI;
     nsCOMPtr<nsIURI> baseURI;
@@ -1965,22 +1950,22 @@ Loader::DoSheetComplete(SheetLoadData* a
           break;
         }
         data = data->mNext;
       }
 #ifdef MOZ_XUL
       if (IsChromeURI(aLoadData->mURI)) {
         nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
         if (cache && cache->IsEnabled()) {
-          // Always store our latest sheet in the cache so that old,
-          // unreferenced sheet objects can be freed.
-          LOG(("  Putting sheet in XUL prototype cache"));
-          NS_ASSERTION(sheet->IsComplete(),
-                       "Should only be caching complete sheets");
-          cache->PutStyleSheet(sheet);
+          if (!cache->GetStyleSheet(aLoadData->mURI)) {
+            LOG(("  Putting sheet in XUL prototype cache"));
+            NS_ASSERTION(sheet->IsComplete(),
+                         "Should only be caching complete sheets");
+            cache->PutStyleSheet(sheet);
+          }
         }
       }
       else {
 #endif
         URIPrincipalReferrerPolicyAndCORSModeHashKey key(aLoadData->mURI,
                                            aLoadData->mLoaderPrincipal,
                                            aLoadData->mSheet->GetCORSMode(),
                                            aLoadData->mSheet->GetReferrerPolicy());