Bug 1440177 - Part 3: Preallocate a small number of PaintedLayerData objects and only resize the mPaintedLayerDataStack once. r?jnicol draft
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 15 Feb 2018 14:45:35 +1300
changeset 762222 a136e473da15901a9683d5ccf145ade9dc987eba
parent 762221 72b4a74dc82abc29eb94bdc464498f22d99707bc
child 762223 96a378972755cf43621e9a09e2f92eeeb20ee92e
push id101106
push usermwoodrow@mozilla.com
push dateThu, 01 Mar 2018 22:19:48 +0000
reviewersjnicol
bugs1440177
milestone60.0a1
Bug 1440177 - Part 3: Preallocate a small number of PaintedLayerData objects and only resize the mPaintedLayerDataStack once. r?jnicol MozReview-Commit-ID: 4RvU35pBz3z
layout/painting/FrameLayerBuilder.cpp
--- a/layout/painting/FrameLayerBuilder.cpp
+++ b/layout/painting/FrameLayerBuilder.cpp
@@ -833,21 +833,16 @@ public:
 
   /**
    * Finish all children.
    */
   void FinishAllChildren() { FinishAllChildren(true); }
 
 protected:
   /**
-   * Finish the topmost item in mPaintedLayerDataStack and pop it from the
-   * stack.
-   */
-  void PopPaintedLayerData();
-  /**
    * Finish all items in mPaintedLayerDataStack and clear the stack.
    */
   void PopAllPaintedLayerData();
   /**
    * Finish all of our child nodes, but don't touch mPaintedLayerDataStack.
    */
   void FinishAllChildren(bool aThisNodeNeedsAccurateVisibleAboveRegion);
   /**
@@ -858,17 +853,17 @@ protected:
 
   PaintedLayerDataTree& mTree;
   PaintedLayerDataNode* mParent;
   AnimatedGeometryRoot* mAnimatedGeometryRoot;
 
   /**
    * Our contents: a PaintedLayerData stack and our child nodes.
    */
-  nsTArray<PaintedLayerData> mPaintedLayerDataStack;
+  AutoTArray<PaintedLayerData, 3> mPaintedLayerDataStack;
 
   /**
    * UniquePtr is used here in the sense of "unique ownership", i.e. there is
    * only one owner. Not in the sense of "this is the only pointer to the
    * node": There are two other, non-owning, pointers to our child nodes: The
    * node's respective children point to their parent node with their mParent
    * pointer, and the tree keeps a map of animated geometry root to node in its
    * mNodes member. These outside pointers are the reason that mChildren isn't
@@ -2909,33 +2904,25 @@ void
 PaintedLayerDataNode::SetAllDrawingAbove()
 {
   PopAllPaintedLayerData();
   mAllDrawingAboveBackground = true;
   mVisibleAboveBackgroundRegion.SetEmpty();
 }
 
 void
-PaintedLayerDataNode::PopPaintedLayerData()
-{
-  MOZ_ASSERT(!mPaintedLayerDataStack.IsEmpty());
-  size_t lastIndex = mPaintedLayerDataStack.Length() - 1;
-  PaintedLayerData& data = mPaintedLayerDataStack[lastIndex];
-  mTree.ContState().FinishPaintedLayerData(data, [this, &data, lastIndex]() {
-    return this->FindOpaqueBackgroundColor(data.mVisibleRegion, lastIndex);
-  });
-  mPaintedLayerDataStack.RemoveElementAt(lastIndex);
-}
-
-void
 PaintedLayerDataNode::PopAllPaintedLayerData()
 {
-  while (!mPaintedLayerDataStack.IsEmpty()) {
-    PopPaintedLayerData();
-  }
+  for (int32_t index = mPaintedLayerDataStack.Length() - 1; index >= 0; index--) {
+    PaintedLayerData& data = mPaintedLayerDataStack[index];
+    mTree.ContState().FinishPaintedLayerData(data, [this, &data, index]() {
+      return this->FindOpaqueBackgroundColor(data.mVisibleRegion, index);
+    });
+  }
+  mPaintedLayerDataStack.Clear();
 }
 
 nsDisplayListBuilder*
 PaintedLayerDataTree::Builder() const
 {
   return mContainerState.Builder();
 }