Bug 1452525 - Deduplicate proto bindings, not bindings. r=xidorn, a=RyanVM
☠☠ backed out by 5ee0d4fb20f4 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 09 Apr 2018 15:25:41 +0200
changeset 463115 567b3f0eaddfdcf59187662480bd5dc69b6d3c8f
parent 463114 64c9c9119d105548f38b6eb731c6b85b7ff2094b
child 463116 70432546852c4ad08fbbd076917eabddd09dc1c5
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn, RyanVM
bugs1452525
milestone60.0
Bug 1452525 - Deduplicate proto bindings, not bindings. r=xidorn, a=RyanVM 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
@@ -717,36 +717,37 @@ nsBindingManager::WalkRules(nsIStyleRule
   // in the loop.
   *aCutOffInheritance = (content != nullptr);
 
   return NS_OK;
 }
 #endif
 
 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;
 }
 
@@ -788,18 +789,18 @@ nsBindingManager::MediumFeaturesChanged(
   MOZ_CRASH("old style system disabled");
   return false;
 #endif
 }
 
 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
@@ -173,19 +173,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
@@ -254,21 +254,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());
 }
@@ -290,19 +288,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);
 
@@ -1310,22 +1308,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();
@@ -1524,19 +1522,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;
 }