Bug 1339627 Part 1: Add a Servo-specific StyleSheet table to nsXULPrototypeCache. r=heycam
authorBrad Werth <bwerth@mozilla.com>
Mon, 06 Mar 2017 14:59:37 -0800
changeset 494402 f7367db2913f24bf9d9eaa5625d25c1444ac7bfc
parent 494401 1465a237d393fe74b7268d5c5f546b178a3d6642
child 494403 817642eb6e45ad0f9e91310d115e53b52432046a
push id48023
push userjwwang@mozilla.com
push dateTue, 07 Mar 2017 02:32:15 +0000
reviewersheycam
bugs1339627
milestone54.0a1
Bug 1339627 Part 1: Add a Servo-specific StyleSheet table to nsXULPrototypeCache. r=heycam MozReview-Commit-ID: 98dUNnccdn1
dom/xul/nsXULPrototypeCache.cpp
dom/xul/nsXULPrototypeCache.h
layout/style/Loader.cpp
--- a/dom/xul/nsXULPrototypeCache.cpp
+++ b/dom/xul/nsXULPrototypeCache.cpp
@@ -184,27 +184,36 @@ nsXULPrototypeCache::PutPrototype(nsXULP
     aDocument->GetURI()->CloneIgnoringRef(getter_AddRefs(uri));
 
     // Put() releases any old value and addrefs the new one
     mPrototypeTable.Put(uri, aDocument);
 
     return NS_OK;
 }
 
+mozilla::StyleSheet*
+nsXULPrototypeCache::GetStyleSheet(nsIURI* aURI,
+                                   StyleBackendType aType)
+{
+    StyleSheetTable& table = TableForBackendType(aType);
+    return table.GetWeak(aURI);
+}
+
 nsresult
-nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet)
+nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet,
+                                   StyleBackendType aType)
 {
     nsIURI* uri = aStyleSheet->GetSheetURI();
 
-    mStyleSheetTable.Put(uri, aStyleSheet);
+    StyleSheetTable& table = TableForBackendType(aType);
+    table.Put(uri, aStyleSheet);
 
     return NS_OK;
 }
 
-
 JSScript*
 nsXULPrototypeCache::GetScript(nsIURI* aURI)
 {
     return mScriptTable.Get(aURI);
 }
 
 nsresult
 nsXULPrototypeCache::PutScript(nsIURI* aURI,
@@ -249,21 +258,26 @@ nsXULPrototypeCache::FlushSkinFiles()
     nsAutoCString str;
     iter.Key()->GetPath(str);
     if (strncmp(str.get(), "/skin", 5) == 0) {
       iter.Remove();
     }
   }
 
   // Now flush out our skin stylesheets from the cache.
-  for (auto iter = mStyleSheetTable.Iter(); !iter.Done(); iter.Next()) {
-    nsAutoCString str;
-    iter.Data()->GetSheetURI()->GetPath(str);
-    if (strncmp(str.get(), "/skin", 5) == 0) {
-      iter.Remove();
+  mozilla::StyleBackendType tableTypes[] = { StyleBackendType::Gecko,
+                                             StyleBackendType::Servo };
+  for (auto tableType : tableTypes) {
+    StyleSheetTable& table = TableForBackendType(tableType);
+    for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
+      nsAutoCString str;
+      iter.Data()->GetSheetURI()->GetPath(str);
+      if (strncmp(str.get(), "/skin", 5) == 0) {
+        iter.Remove();
+      }
     }
   }
 
   // Iterate over all the remaining XBL and make sure cached
   // scoped skin stylesheets are flushed and refetched by the
   // prototype bindings.
   for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
     iter.Data()->FlushSkinStylesheets();
@@ -276,17 +290,18 @@ nsXULPrototypeCache::FlushScripts()
     mScriptTable.Clear();
 }
 
 void
 nsXULPrototypeCache::Flush()
 {
     mPrototypeTable.Clear();
     mScriptTable.Clear();
-    mStyleSheetTable.Clear();
+    mGeckoStyleSheetTable.Clear();
+    mServoStyleSheetTable.Clear();
     mXBLDocTable.Clear();
 }
 
 
 bool
 nsXULPrototypeCache::IsEnabled()
 {
     return !gDisableXULCache;
--- a/dom/xul/nsXULPrototypeCache.h
+++ b/dom/xul/nsXULPrototypeCache.h
@@ -69,25 +69,25 @@ public:
         return mXBLDocTable.GetWeak(aURL);
     }
     nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
 
     /**
      * Get a style sheet by URI. If the style sheet is not in the cache,
      * returns nullptr.
      */
-    mozilla::StyleSheet* GetStyleSheet(nsIURI* aURI) {
-        return mStyleSheetTable.GetWeak(aURI);
-    }
+    mozilla::StyleSheet* GetStyleSheet(nsIURI* aURI,
+                                       mozilla::StyleBackendType aType);
 
     /**
      * Store a style sheet in the cache. The key, style sheet's URI is obtained
      * from the style sheet itself.
      */
-    nsresult PutStyleSheet(mozilla::StyleSheet* aStyleSheet);
+    nsresult PutStyleSheet(mozilla::StyleSheet* aStyleSheet,
+                           mozilla::StyleBackendType aType);
 
     /**
      * Write the XUL prototype document to a cache file. The proto must be
      * fully loaded.
      */
     nsresult WritePrototype(nsXULPrototypeDocument* aPrototypeDocument);
 
     /**
@@ -117,18 +117,25 @@ protected:
 
     nsXULPrototypeCache();
     virtual ~nsXULPrototypeCache();
 
     static nsXULPrototypeCache* sInstance;
 
     void FlushSkinFiles();
 
+    typedef nsRefPtrHashtable<nsURIHashKey, mozilla::StyleSheet> StyleSheetTable;
+    StyleSheetTable& TableForBackendType(mozilla::StyleBackendType aType) {
+      return aType == mozilla::StyleBackendType::Gecko ? mGeckoStyleSheetTable
+                                                       : mServoStyleSheetTable;
+    }
+
     nsRefPtrHashtable<nsURIHashKey,nsXULPrototypeDocument>   mPrototypeTable; // owns the prototypes
-    nsRefPtrHashtable<nsURIHashKey,mozilla::StyleSheet>      mStyleSheetTable;
+    StyleSheetTable                                          mGeckoStyleSheetTable;
+    StyleSheetTable                                          mServoStyleSheetTable;
     nsJSThingHashtable<nsURIHashKey, JSScript*>              mScriptTable;
     nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo>        mXBLDocTable;
 
     // URIs already written to the startup cache, to prevent double-caching.
     nsTHashtable<nsURIHashKey>                               mStartupCacheURITable;
 
     nsInterfaceHashtable<nsURIHashKey, nsIStorageStream>     mOutputStreamTable;
     nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream> mInputStreamTable;
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1117,17 +1117,17 @@ Loader::CreateSheet(nsIURI* aURI,
 #ifdef MOZ_XUL
     // The XUL cache is a singleton that only holds Gecko-style sheets, so
     // only use the cache if the loader is also Gecko.
     if (IsChromeURI(aURI) &&
         GetStyleBackendType() == StyleBackendType::Gecko) {
       nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
       if (cache) {
         if (cache->IsEnabled()) {
-          sheet = cache->GetStyleSheet(aURI);
+          sheet = cache->GetStyleSheet(aURI, GetStyleBackendType());
           LOG(("  From XUL cache: %p", sheet.get()));
         }
       }
     }
 #endif
 
     bool fromCompleteSheets = false;
     if (!sheet) {
@@ -1956,21 +1956,21 @@ Loader::DoSheetComplete(SheetLoadData* a
       }
       data = data->mNext;
     }
 #ifdef MOZ_XUL
     if (IsChromeURI(aLoadData->mURI) &&
         GetStyleBackendType() == StyleBackendType::Gecko) {
       nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
       if (cache && cache->IsEnabled()) {
-        if (!cache->GetStyleSheet(aLoadData->mURI)) {
+        if (!cache->GetStyleSheet(aLoadData->mURI, GetStyleBackendType())) {
           LOG(("  Putting sheet in XUL prototype cache"));
           NS_ASSERTION(sheet->IsComplete(),
                        "Should only be caching complete sheets");
-          cache->PutStyleSheet(sheet);
+          cache->PutStyleSheet(sheet, GetStyleBackendType());
         }
       }
     }
     else {
 #endif
       URIPrincipalReferrerPolicyAndCORSModeHashKey key(aLoadData->mURI,
                                          aLoadData->mLoaderPrincipal,
                                          aLoadData->mSheet->GetCORSMode(),