Bug 1440177 - Part 3: Preallocate a small number of PaintedLayerData objects and only resize the mPaintedLayerDataStack once. r?jnicol
MozReview-Commit-ID: 4RvU35pBz3z
--- 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();
}