diff --git a/layout/painting/DisplayItemClipChain.h b/layout/painting/DisplayItemClipChain.h index eb7f9a3a3ab6..d12d6f53733b 100644 --- a/layout/painting/DisplayItemClipChain.h +++ b/layout/painting/DisplayItemClipChain.h @@ -67,10 +67,12 @@ struct DisplayItemClipChain DisplayItemClipChain(const DisplayItemClip& aClip, const ActiveScrolledRoot* aASR, - const DisplayItemClipChain* aParent) + const DisplayItemClipChain* aParent, + DisplayItemClipChain* aNextClipChainToDestroy) : mClip(aClip) , mASR(aASR) , mParent(aParent) + , mNextClipChainToDestroy(aNextClipChainToDestroy) #ifdef DEBUG , mOnStack(true) #endif @@ -79,6 +81,7 @@ struct DisplayItemClipChain DisplayItemClipChain() : mASR(nullptr) + , mNextClipChainToDestroy(nullptr) #ifdef DEBUG , mOnStack(true) #endif @@ -89,6 +92,7 @@ struct DisplayItemClipChain const ActiveScrolledRoot* mASR; RefPtr mParent; uint32_t mRefCount = 0; + DisplayItemClipChain* mNextClipChainToDestroy; #ifdef DEBUG bool mOnStack; #endif diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index ab1b14655e8b..1a2085a784dd 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -978,6 +978,7 @@ nsDisplayListBuilder::nsDisplayListBuilder(nsIFrame* aReferenceFrame, , mDirtyRect(-1, -1, -1, -1) , mGlassDisplayItem(nullptr) , mScrollInfoItemsForHoisting(nullptr) + , mFirstClipChainToDestroy(nullptr) , mActiveScrolledRootForRootScrollframe(nullptr) , mMode(aMode) , mCurrentScrollParentId(FrameMetrics::NULL_SCROLL_ID) @@ -1252,8 +1253,11 @@ nsDisplayListBuilder::~nsDisplayListBuilder() "All presshells should have been exited"); NS_ASSERTION(!mCurrentTableItem, "No table item should be active"); - for (DisplayItemClipChain* c : mClipChainsToDestroy) { + DisplayItemClipChain* c = mFirstClipChainToDestroy; + while (c) { + DisplayItemClipChain* next = c->mNextClipChainToDestroy; c->DisplayItemClipChain::~DisplayItemClipChain(); + c = next; } MOZ_COUNT_DTOR(nsDisplayListBuilder); @@ -1442,18 +1446,19 @@ nsDisplayListBuilder::FreeClipChains() // Iterate the clip chains from newest to oldest (forward // iteration), so that we destroy descendants first which // will drop the ref count on their ancestors. - auto it = mClipChainsToDestroy.begin(); + DisplayItemClipChain** indirect = &mFirstClipChainToDestroy; - while (it != mClipChainsToDestroy.end()) { - DisplayItemClipChain* clip = *it; + while (*indirect) { + if (!(*indirect)->mRefCount) { + DisplayItemClipChain* next = (*indirect)->mNextClipChainToDestroy; - if (!clip->mRefCount) { - mClipDeduplicator.erase(clip); - it = mClipChainsToDestroy.erase(it); - clip->DisplayItemClipChain::~DisplayItemClipChain(); - Destroy(DisplayItemType::TYPE_ZERO, clip); + mClipDeduplicator.erase(*indirect); + (*indirect)->DisplayItemClipChain::~DisplayItemClipChain(); + Destroy(DisplayItemType::TYPE_ZERO, *indirect); + + *indirect = next; } else { - ++it; + indirect = &(*indirect)->mNextClipChainToDestroy; } } } @@ -1620,7 +1625,10 @@ nsDisplayListBuilder::AllocateDisplayItemClipChain( MOZ_ASSERT(!(aParent && aParent->mOnStack)); void* p = Allocate(sizeof(DisplayItemClipChain), DisplayItemType::TYPE_ZERO); DisplayItemClipChain* c = - new (KnownNotNull, p) DisplayItemClipChain(aClip, aASR, aParent); + new (KnownNotNull, p) DisplayItemClipChain(aClip, + aASR, + aParent, + mFirstClipChainToDestroy); #ifdef DEBUG c->mOnStack = false; #endif @@ -1635,7 +1643,7 @@ nsDisplayListBuilder::AllocateDisplayItemClipChain( Destroy(DisplayItemType::TYPE_ZERO, c); return *(result.first); } - mClipChainsToDestroy.emplace_front(c); + mFirstClipChainToDestroy = c; return c; } diff --git a/layout/painting/nsDisplayList.h b/layout/painting/nsDisplayList.h index 6ebd21c3b490..d1ae7cba3305 100644 --- a/layout/painting/nsDisplayList.h +++ b/layout/painting/nsDisplayList.h @@ -2122,7 +2122,7 @@ private: DisplayItemClipChainHasher, DisplayItemClipChainEqualer> mClipDeduplicator; - std::list mClipChainsToDestroy; + DisplayItemClipChain* mFirstClipChainToDestroy; nsTArray mTemporaryItems; const ActiveScrolledRoot* mActiveScrolledRootForRootScrollframe; nsDisplayListBuilderMode mMode;