Bug 1452525: Deduplicate proto bindings, not bindings. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 09 Apr 2018 15:25:41 +0200
changeset 779206 b48cc23827b1110da4a8fa1726c7190bd4d05500
parent 779205 bc2e4f1333aea9a99b7059d41a1d6fcb66e7f05d
child 779430 8db97b7a27ae160af70dcbf038b29b801d0c0367
push id105694
push userbmo:emilio@crisal.io
push dateMon, 09 Apr 2018 13:27:52 +0000
reviewersxidorn
bugs1452525
milestone61.0a1
Bug 1452525: Deduplicate proto bindings, not bindings. r?xidorn MozReview-Commit-ID: 2NWALzUhDjn
dom/xbl/nsBindingManager.cpp
dom/xbl/nsBindingManager.h
layout/style/ServoStyleSet.cpp
--- a/dom/xbl/nsBindingManager.cpp
+++ b/dom/xbl/nsBindingManager.cpp
@@ -662,49 +662,50 @@ nsBindingManager::GetBindingImplementati
   }
 
   *aResult = nullptr;
   return NS_NOINTERFACE;
 }
 
 
 bool
-nsBindingManager::EnumerateBoundContentBindings(
-  const BoundContentBindingCallback& aCallback) const
+nsBindingManager::EnumerateBoundContentProtoBindings(
+  const BoundContentProtoBindingCallback& aCallback) const
 {
   if (!mBoundContentSet) {
     return true;
   }
 
-  nsTHashtable<nsPtrHashKey<nsXBLBinding>> bindings;
+  nsTHashtable<nsPtrHashKey<nsXBLPrototypeBinding>> bindings;
   for (auto iter = mBoundContentSet->Iter(); !iter.Done(); iter.Next()) {
     nsIContent* boundContent = iter.Get()->GetKey();
     for (nsXBLBinding* binding = boundContent->GetXBLBinding();
          binding;
          binding = binding->GetBaseBinding()) {
+      nsXBLPrototypeBinding* proto = binding->PrototypeBinding();
       // If we have already invoked the callback with a binding, we
       // should have also invoked it for all its base bindings, so we
       // don't need to continue this loop anymore.
-      if (!bindings.EnsureInserted(binding)) {
+      if (!bindings.EnsureInserted(proto)) {
         break;
       }
-      if (!aCallback(binding)) {
+      if (!aCallback(proto)) {
         return false;
       }
     }
   }
 
   return true;
 }
 
 void
 nsBindingManager::AppendAllSheets(nsTArray<StyleSheet*>& aArray)
 {
-  EnumerateBoundContentBindings([&aArray](nsXBLBinding* aBinding) {
-    aBinding->PrototypeBinding()->AppendStyleSheetsTo(aArray);
+  EnumerateBoundContentProtoBindings([&aArray](nsXBLPrototypeBinding* aProto) {
+    aProto->AppendStyleSheetsTo(aArray);
     return true;
   });
 }
 
 static void
 InsertAppendedContent(XBLChildrenElement* aPoint,
                       nsIContent* aFirstNewContent)
 {
--- a/dom/xbl/nsBindingManager.h
+++ b/dom/xbl/nsBindingManager.h
@@ -154,19 +154,21 @@ public:
   void DropDocumentReference();
 
   nsIContent* FindNestedSingleInsertionPoint(nsIContent* aContainer, bool* aMulti);
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   // Enumerate each bound content's bindings (including its base bindings)
   // in mBoundContentSet. Return false from the callback to stop enumeration.
-  using BoundContentBindingCallback = std::function<bool (nsXBLBinding*)>;
-  bool EnumerateBoundContentBindings(
-    const BoundContentBindingCallback& aCallback) const;
+  using BoundContentProtoBindingCallback =
+    std::function<bool (nsXBLPrototypeBinding*)>;
+
+  bool EnumerateBoundContentProtoBindings(
+      const BoundContentProtoBindingCallback&) const;
 
 protected:
   nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
   nsresult SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aResult);
 
   // Called by ContentAppended and ContentInserted to handle a single child
   // insertion.  aChild must not be null.  aContainer may be null.
   // aAppend is true if this child is being appended, not inserted.
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -238,21 +238,19 @@ ServoStyleSet::InvalidateStyleForDocumen
   // instead and run invalidation individually, passing mRawSet for the UA /
   // User sheets.
   AutoTArray<RawServoAuthorStylesBorrowed, 20> nonDocumentStyles;
 
   EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
     nonDocumentStyles.AppendElement(aShadowRoot.ServoStyles());
   });
 
-  // FIXME(emilio): When bug 1425759 is fixed we need to enumerate ShadowRoots
-  // too.
-  mDocument->BindingManager()->EnumerateBoundContentBindings(
-    [&](nsXBLBinding* aBinding) {
-      if (auto* authorStyles = aBinding->PrototypeBinding()->GetServoStyles()) {
+  mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+    [&](nsXBLPrototypeBinding* aProto) {
+      if (auto* authorStyles = aProto->GetServoStyles()) {
         nonDocumentStyles.AppendElement(authorStyles);
       }
       return true;
     });
 
   Servo_InvalidateStyleForDocStateChanges(
     root, mRawSet.get(), &nonDocumentStyles, aStatesChanged.ServoValue());
 }
@@ -274,19 +272,19 @@ ServoStyleSet::MediumFeaturesChanged(Med
 {
   AutoTArray<RawServoAuthorStylesBorrowedMut, 20> nonDocumentStyles;
 
   EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
     nonDocumentStyles.AppendElement(aShadowRoot.ServoStyles());
   });
 
   // FIXME(emilio): This is broken for XBL. See bug 1406875.
-  mDocument->BindingManager()->EnumerateBoundContentBindings(
-    [&](nsXBLBinding* aBinding) {
-      if (auto* authorStyles = aBinding->PrototypeBinding()->GetServoStyles()) {
+  mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+    [&](nsXBLPrototypeBinding* aProto) {
+      if (auto* authorStyles = aProto->GetServoStyles()) {
         nonDocumentStyles.AppendElement(authorStyles);
       }
       return true;
     });
 
   bool mayAffectDefaultStyle =
     bool(aReason & kMediaFeaturesAffectingDefaultStyle);
 
@@ -1277,22 +1275,22 @@ ServoStyleSet::EnsureUniqueInnerOnCSSShe
 
   EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
     for (auto index : IntegerRange(aShadowRoot.SheetCount())) {
       queue.AppendElement(
         MakePair(aShadowRoot.SheetAt(index), SheetOwner { &aShadowRoot }));
     }
   });
 
-  mDocument->BindingManager()->EnumerateBoundContentBindings(
-      [&](nsXBLBinding* aBinding) {
+  mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+      [&](nsXBLPrototypeBinding* aProto) {
         AutoTArray<StyleSheet*, 3> sheets;
-        aBinding->PrototypeBinding()->AppendStyleSheetsTo(sheets);
+        aProto->AppendStyleSheetsTo(sheets);
         for (auto* sheet : sheets) {
-          queue.AppendElement(MakePair(sheet, SheetOwner { aBinding->PrototypeBinding() }));
+          queue.AppendElement(MakePair(sheet, SheetOwner { aProto }));
         }
         return true;
       });
 
   bool anyNonDocStyleChanged = false;
   while (!queue.IsEmpty()) {
     uint32_t idx = queue.Length() - 1;
     auto* sheet = queue[idx].first();
@@ -1483,19 +1481,19 @@ ServoStyleSet::UpdateStylist()
 
   if (MOZ_UNLIKELY(mStylistState & StylistState::XBLStyleSheetsDirty)) {
     MOZ_ASSERT(GetPresContext(), "How did they get dirty?");
 
     EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
       Servo_AuthorStyles_Flush(aShadowRoot.ServoStyles(), mRawSet.get());
     });
 
-    mDocument->BindingManager()->EnumerateBoundContentBindings(
-      [&](nsXBLBinding* aBinding) {
-        if (auto* authorStyles = aBinding->PrototypeBinding()->GetServoStyles()) {
+    mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+      [&](nsXBLPrototypeBinding* aProto) {
+        if (auto* authorStyles = aProto->GetServoStyles()) {
           Servo_AuthorStyles_Flush(authorStyles, mRawSet.get());
         }
         return true;
       });
   }
 
   mStylistState = StylistState::NotDirty;
 }