Bug 1407888 part 2 - Make ServoStyleRuleMap::FillTableFromStyleSheet not make unique inner. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Thu, 12 Oct 2017 18:56:02 +1100
changeset 679817 070074af3e7af4e6d67ebd39ed461639bf319a7e
parent 679645 eaf00ce9c9fd41f5799c6d8c6ec44972fa73dc11
child 735685 b279fed4c31cdcc8b16901022f7b4dbdd0d36032
push id84315
push userxquan@mozilla.com
push dateFri, 13 Oct 2017 03:27:34 +0000
reviewersheycam
bugs1407888
milestone58.0a1
Bug 1407888 part 2 - Make ServoStyleRuleMap::FillTableFromStyleSheet not make unique inner. r?heycam MozReview-Commit-ID: 1I7sawfjcnl
layout/inspector/ServoStyleRuleMap.cpp
layout/style/ServoStyleSet.h
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
layout/style/StyleSheetInlines.h
--- a/layout/inspector/ServoStyleRuleMap.cpp
+++ b/layout/inspector/ServoStyleRuleMap.cpp
@@ -6,16 +6,17 @@
 
 #include "mozilla/ServoStyleRuleMap.h"
 
 #include "mozilla/css/GroupRule.h"
 #include "mozilla/IntegerRange.h"
 #include "mozilla/ServoStyleRule.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/ServoImportRule.h"
+#include "mozilla/StyleSheetInlines.h"
 
 #include "nsDocument.h"
 #include "nsStyleSheetService.h"
 
 namespace mozilla {
 
 ServoStyleRuleMap::ServoStyleRuleMap(ServoStyleSet* aStyleSet)
   : mStyleSet(aStyleSet)
@@ -170,13 +171,16 @@ ServoStyleRuleMap::FillTableFromRuleList
     FillTableFromRule(aRuleList->GetRule(i));
   }
 }
 
 void
 ServoStyleRuleMap::FillTableFromStyleSheet(ServoStyleSheet* aSheet)
 {
   if (aSheet->IsComplete()) {
-    FillTableFromRuleList(aSheet->GetCssRulesInternal());
+    // XBL stylesheets are not expected to ever change, so it's a waste
+    // to make its inner unique.
+    FillTableFromRuleList(aSheet->GetCssRulesInternal(
+        /* aRequireUniqueInner = */ !mStyleSet->IsForXBL()));
   }
 }
 
 } // namespace mozilla
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -473,30 +473,30 @@ public:
    */
   already_AddRefed<ServoStyleContext>
   ReparentStyleContext(ServoStyleContext* aStyleContext,
                        ServoStyleContext* aNewParent,
                        ServoStyleContext* aNewParentIgnoringFirstLine,
                        ServoStyleContext* aNewLayoutParent,
                        Element* aElement);
 
+  bool IsMaster() const { return mKind == Kind::Master; }
+  bool IsForXBL() const { return mKind == Kind::ForXBL; }
+
 private:
   friend class AutoSetInServoTraversal;
   friend class AutoPrepareTraversal;
 
   bool ShouldTraverseInParallel() const;
 
   /**
    * Gets the pending snapshots to handle from the restyle manager.
    */
   const SnapshotTable& Snapshots();
 
-  bool IsMaster() const { return mKind == Kind::Master; }
-  bool IsForXBL() const { return mKind == Kind::ForXBL; }
-
   /**
    * Resolve all ServoDeclarationBlocks attached to mapped
    * presentation attributes cached on the document.
    *
    * Call this before jumping into Servo's style system.
    */
   void ResolveMappedAttrDeclarationBlocks();
 
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -388,20 +388,25 @@ ServoStyleSheet::Clone(StyleSheet* aClon
     static_cast<ServoStyleSheet*>(aCloneParent),
     aCloneOwnerRule,
     aCloneDocument,
     aCloneOwningNode);
   return clone.forget();
 }
 
 ServoCSSRuleList*
-ServoStyleSheet::GetCssRulesInternal()
+ServoStyleSheet::GetCssRulesInternal(bool aRequireUniqueInner)
 {
   if (!mRuleList) {
-    EnsureUniqueInner();
+    MOZ_ASSERT(aRequireUniqueInner || !mDocument,
+               "Not requiring unique inner for stylesheet associated "
+               "with document may have undesired behavior");
+    if (aRequireUniqueInner) {
+      EnsureUniqueInner();
+    }
 
     RefPtr<ServoCssRules> rawRules =
       Servo_StyleSheet_GetRules(Inner()->mContents).Consume();
     MOZ_ASSERT(rawRules);
     mRuleList = new ServoCSSRuleList(rawRules.forget(), this);
   }
   return mRuleList;
 }
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -115,17 +115,17 @@ public:
     nsINode* aCloneOwningNode) const final;
 
   // nsICSSLoaderObserver interface
   NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
                               nsresult aStatus) final;
 
   // Internal GetCssRules method which do not have security check and
   // completelness check.
-  ServoCSSRuleList* GetCssRulesInternal();
+  ServoCSSRuleList* GetCssRulesInternal(bool aRequireUniqueInner = true);
 
   // Returns the stylesheet's Servo origin as an OriginFlags value.
   OriginFlags GetOrigin();
 
 protected:
   virtual ~ServoStyleSheet();
 
   void LastRelease();
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -445,17 +445,17 @@ StyleSheet::DropStyleSet(const StyleSetH
 
 void
 StyleSheet::EnsureUniqueInner()
 {
   MOZ_ASSERT(mInner->mSheets.Length() != 0,
              "unexpected number of outers");
   mDirty = true;
 
-  if (mInner->mSheets.Length() == 1) {
+  if (HasUniqueInner()) {
     // already unique
     return;
   }
 
   StyleSheetInfo* clone = mInner->CloneFor(this);
   MOZ_ASSERT(clone);
   mInner->RemoveSheet(this);
   mInner = clone;
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -133,16 +133,17 @@ public:
 
   virtual already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
                                              dom::CSSImportRule* aCloneOwnerRule,
                                              nsIDocument* aCloneDocument,
                                              nsINode* aCloneOwningNode) const = 0;
 
   bool IsModified() const { return mDirty; }
 
+  inline bool HasUniqueInner() const;
   void EnsureUniqueInner();
 
   // Append all of this sheet's child sheets to aArray.
   void AppendAllChildSheets(nsTArray<StyleSheet*>& aArray);
 
   // style sheet owner info
   enum DocumentAssociationMode : uint8_t {
     // OwnedByDocument means mDocument owns us (possibly via a chain of other
--- a/layout/style/StyleSheetInlines.h
+++ b/layout/style/StyleSheetInlines.h
@@ -124,11 +124,17 @@ StyleSheet::GetReferrerPolicy() const
 }
 
 void
 StyleSheet::GetIntegrity(dom::SRIMetadata& aResult) const
 {
   aResult = SheetInfo().mIntegrity;
 }
 
+bool
+StyleSheet::HasUniqueInner() const
+{
+  return mInner->mSheets.Length() == 1;
+}
+
 }
 
 #endif // mozilla_StyleSheetInlines_h