Bug 1367217 - Merge ClearAllUndisplayedContentIn / ClearAllDisplayContentsIn to avoid doing duplicated work. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Thu, 08 Jun 2017 12:48:31 +0200
changeset 411076 ee20b7f985f5471b1a095f030505796ed97365b3
parent 411075 bacd825eed43f60d48e8e9a86987ae0043b672b2
child 411077 d1a431f894c29fe4ef5ebde3dc6431d1566307d2
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1367217
milestone55.0a1
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
Bug 1367217 - Merge ClearAllUndisplayedContentIn / ClearAllDisplayContentsIn to avoid doing duplicated work. r=dholbert MozReview-Commit-ID: 2oYliXTf1nr
layout/base/nsFrameManager.cpp
layout/base/nsFrameManager.h
--- a/layout/base/nsFrameManager.cpp
+++ b/layout/base/nsFrameManager.cpp
@@ -271,35 +271,47 @@ nsFrameManager::ClearUndisplayedContentI
   }
 
 #ifdef DEBUG_UNDISPLAYED_MAP
   printf( "not found.\n");
 #endif
 }
 
 void
-nsFrameManager::ClearAllUndisplayedContentIn(nsIContent* aParentContent)
+nsFrameManager::ClearAllMapsFor(nsIContent* aParentContent)
 {
-#ifdef DEBUG_UNDISPLAYED_MAP
+#if defined(DEBUG_UNDISPLAYED_MAP) || defined(DEBUG_DISPLAY_CONTENTS_MAP)
   static int i = 0;
-  printf("ClearAllUndisplayedContentIn(%d): parent=%p \n", i++, (void*)aParentContent);
+  printf("ClearAllMapsFor(%d): parent=%p \n", i++, aParentContent);
 #endif
 
   if (mUndisplayedMap) {
     mUndisplayedMap->RemoveNodesFor(aParentContent);
   }
+  if (mDisplayContentsMap) {
+    nsAutoPtr<LinkedList<UndisplayedNode>> list =
+      mDisplayContentsMap->UnlinkNodesFor(aParentContent);
+    if (list) {
+      while (UndisplayedNode* node = list->popFirst()) {
+        ClearAllMapsFor(node->mContent);
+        delete node;
+      }
+    }
+  }
 
   // Need to look at aParentContent's content list due to XBL insertions.
   // Nodes in aParentContent's content list do not have aParentContent as a
   // parent, but are treated as children of aParentContent. We iterate over
   // the flattened content list and just ignore any nodes we don't care about.
   FlattenedChildIterator iter(aParentContent);
   for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
-    if (child->GetParent() != aParentContent) {
-      ClearUndisplayedContentIn(child, child->GetParent());
+    auto parent = child->GetParent();
+    if (parent != aParentContent) {
+      ClearUndisplayedContentIn(child, parent);
+      ClearDisplayContentsIn(child, parent);
     }
   }
 }
 
 //----------------------------------------------------------------------
 
 void
 nsFrameManager::SetDisplayContents(nsIContent* aContent,
@@ -336,59 +348,25 @@ nsFrameManager::ClearDisplayContentsIn(n
       mDisplayContentsMap->RemoveNodeFor(aParentContent, node);
 
 #ifdef DEBUG_DISPLAY_CONTENTS_MAP
       printf( "REMOVED!\n");
 #endif
       // make sure that there are no more entries for the same content
       MOZ_ASSERT(!GetDisplayContentsStyleFor(aContent),
                  "Found more entries for aContent after removal");
-      ClearAllDisplayContentsIn(aContent);
-      ClearAllUndisplayedContentIn(aContent);
+      ClearAllMapsFor(aContent);
       return;
     }
   }
 #ifdef DEBUG_DISPLAY_CONTENTS_MAP
   printf( "not found.\n");
 #endif
 }
 
-void
-nsFrameManager::ClearAllDisplayContentsIn(nsIContent* aParentContent)
-{
-#ifdef DEBUG_DISPLAY_CONTENTS_MAP
-  static int i = 0;
-  printf("ClearAllDisplayContentsIn(%d): parent=%p \n", i++, (void*)aParentContent);
-#endif
-
-  if (mDisplayContentsMap) {
-    nsAutoPtr<LinkedList<UndisplayedNode>> list =
-      mDisplayContentsMap->UnlinkNodesFor(aParentContent);
-    if (list) {
-      while (UndisplayedNode* node = list->popFirst()) {
-        ClearAllDisplayContentsIn(node->mContent);
-        ClearAllUndisplayedContentIn(node->mContent);
-        delete node;
-      }
-    }
-  }
-
-  // Need to look at aParentContent's content list due to XBL insertions.
-  // Nodes in aParentContent's content list do not have aParentContent as a
-  // parent, but are treated as children of aParentContent. We iterate over
-  // the flattened content list and just ignore any nodes we don't care about.
-  FlattenedChildIterator iter(aParentContent);
-  for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
-    if (child->GetParent() != aParentContent) {
-      ClearDisplayContentsIn(child, child->GetParent());
-      ClearUndisplayedContentIn(child, child->GetParent());
-    }
-  }
-}
-
 //----------------------------------------------------------------------
 void
 nsFrameManager::AppendFrames(nsContainerFrame* aParentFrame,
                              ChildListID       aListID,
                              nsFrameList&      aFrameList)
 {
   if (aParentFrame->IsAbsoluteContainer() &&
       aListID == aParentFrame->GetAbsoluteListID()) {
@@ -455,18 +433,17 @@ nsFrameManager::RemoveFrame(ChildListID 
 
 //----------------------------------------------------------------------
 
 void
 nsFrameManager::NotifyDestroyingFrame(nsIFrame* aFrame)
 {
   nsIContent* content = aFrame->GetContent();
   if (content && content->GetPrimaryFrame() == aFrame) {
-    ClearAllUndisplayedContentIn(content);
-    ClearAllDisplayContentsIn(content);
+    ClearAllMapsFor(content);
   }
 }
 
 // Capture state for a given frame.
 // Accept a content id here, in some cases we may not have content (scroll position)
 void
 nsFrameManager::CaptureFrameStateFor(nsIFrame* aFrame,
                                      nsILayoutHistoryState* aState)
--- a/layout/base/nsFrameManager.h
+++ b/layout/base/nsFrameManager.h
@@ -93,17 +93,16 @@ public:
   void ChangeUndisplayedContent(nsIContent* aContent,
                                 nsStyleContext* aStyleContext)
   {
     ChangeStyleContextInMap(mUndisplayedMap, aContent, aStyleContext);
   }
 
   void ClearUndisplayedContentIn(nsIContent* aContent,
                                  nsIContent* aParentContent);
-  void ClearAllUndisplayedContentIn(nsIContent* aParentContent);
 
   // display:contents related methods:
   /**
    * Return the registered display:contents style context for aContent, if any.
    */
   nsStyleContext* GetDisplayContentsStyleFor(const nsIContent* aContent)
   {
     if (!mDisplayContentsMap) {
@@ -144,17 +143,16 @@ public:
   }
 
   /**
    * Unregister the display:contents style context for aContent, if any.
    * If found, then also unregister any display:contents and display:none
    * style contexts for its descendants.
    */
   void ClearDisplayContentsIn(nsIContent* aContent, nsIContent* aParentContent);
-  void ClearAllDisplayContentsIn(nsIContent* aParentContent);
 
   // Functions for manipulating the frame model
   void AppendFrames(nsContainerFrame* aParentFrame,
                     ChildListID aListID,
                     nsFrameList& aFrameList);
 
   void InsertFrames(nsContainerFrame* aParentFrame,
                     ChildListID aListID,
@@ -185,16 +183,18 @@ public:
   /*
    * Add/restore state for one frame
    */
   void CaptureFrameStateFor(nsIFrame* aFrame, nsILayoutHistoryState* aState);
 
   void RestoreFrameStateFor(nsIFrame* aFrame, nsILayoutHistoryState* aState);
 
 protected:
+  void ClearAllMapsFor(nsIContent* aParentContent);
+
   static nsStyleContext* GetStyleContextInMap(UndisplayedMap* aMap,
                                               const nsIContent* aContent);
   static mozilla::UndisplayedNode*
     GetUndisplayedNodeInMapFor(UndisplayedMap* aMap,
                                const nsIContent* aContent);
   static mozilla::UndisplayedNode*
     GetAllUndisplayedNodesInMapFor(UndisplayedMap* aMap,
                                    nsIContent* aParentContent);