From 7d9ee615704c0a360d9917bc513804a5c2b8f94d Mon Sep 17 00:00:00 2001 From: Jamie Nicol Date: Tue, 3 Jul 2018 22:39:04 -0400 Subject: [PATCH] Bug 1473379 - Change PaintedLayerData::mAssignedDisplayItems to a std::vector. r=mattwoodrow This allows us to call emplace_back, saving us a move. MozReview-Commit-ID: 4wRiAxl7LSN --HG-- extra : rebase_source : 0ea07c896c2807a65ad7493a22b8e2b61e68aa01 --- layout/painting/FrameLayerBuilder.cpp | 35 +++++++++++++++------------ layout/painting/FrameLayerBuilder.h | 4 +-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/layout/painting/FrameLayerBuilder.cpp b/layout/painting/FrameLayerBuilder.cpp index 03f5ae6a402d..7a49a111a352 100644 --- a/layout/painting/FrameLayerBuilder.cpp +++ b/layout/painting/FrameLayerBuilder.cpp @@ -60,6 +60,9 @@ using namespace mozilla::layers; using namespace mozilla::gfx; +// PaintedLayerData::mAssignedDisplayItems is a std::vector, which is non-memmovable +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::PaintedLayerData); + namespace mozilla { class PaintedDisplayItemLayerUserData; @@ -768,7 +771,7 @@ public: * All the display items that have been assigned to this painted layer. * These items get added by Accumulate(). */ - nsTArray mAssignedDisplayItems; + std::vector mAssignedDisplayItems; }; struct NewLayerEntry { @@ -1706,7 +1709,7 @@ public: // Temporary state only valid during the FrameLayerBuilder's lifetime. // FLB's mPaintedLayerItems is responsible for cleaning these up when // we finish painting to avoid dangling pointers. - nsTArray mItems; + std::vector mItems; nsIFrame* mContainerLayerFrame; bool mHasExplicitLastPaintOffset; @@ -1736,7 +1739,7 @@ FrameLayerBuilder::~FrameLayerBuilder() { GetMaskLayerImageCache()->Sweep(); for (PaintedDisplayItemLayerUserData* userData : mPaintedLayerItems) { - userData->mItems.Clear(); + userData->mItems.clear(); userData->mContainerLayerFrame = nullptr; } MOZ_COUNT_DTOR(FrameLayerBuilder); @@ -3359,7 +3362,7 @@ void ContainerState::FinishPaintedLayerData(PaintedLayerData& aData, FindOpaqueB PaintedDisplayItemLayerUserData* userData = GetPaintedDisplayItemLayerUserData(data->mLayer); NS_ASSERTION(userData, "where did our user data go?"); - userData->mLastItemCount = data->mAssignedDisplayItems.Length(); + userData->mLastItemCount = data->mAssignedDisplayItems.size(); NewLayerEntry* newLayerEntry = &mNewChildLayers[data->mNewChildLayersIndex]; @@ -3647,9 +3650,9 @@ PaintedLayerData::Accumulate(ContainerState* aState, MOZ_ASSERT(!aOpacityIndices.IsEmpty()); aOpacityIndices.RemoveLastElement(); - AssignedDisplayItem item(aItem, aLayerState, - nullptr, aContentRect, aType, hasOpacity); - mAssignedDisplayItems.AppendElement(std::move(item)); + mAssignedDisplayItems.emplace_back( + aItem, aLayerState, nullptr, aContentRect, aType, hasOpacity); + return; } @@ -3686,12 +3689,12 @@ PaintedLayerData::Accumulate(ContainerState* aState, aState->mLayerBuilder->GetOldLayerForFrame(aItem->Frame(), aItem->GetPerFrameKey(), currentData); - AssignedDisplayItem item(aItem, aLayerState, - oldData, aContentRect, aType, hasOpacity); - mAssignedDisplayItems.AppendElement(std::move(item)); + + mAssignedDisplayItems.emplace_back( + aItem, aLayerState, oldData, aContentRect, aType, hasOpacity); if (aType == DisplayItemEntryType::PUSH_OPACITY) { - aOpacityIndices.AppendElement(mAssignedDisplayItems.Length() - 1); + aOpacityIndices.AppendElement(mAssignedDisplayItems.size() - 1); } if (aItem->MustPaintOnContentSide()) { @@ -4848,7 +4851,7 @@ ContainerState::ProcessDisplayItems(nsDisplayList* aList) paintedLayerData->mLayer = layer; PaintedDisplayItemLayerUserData* userData = GetPaintedDisplayItemLayerUserData(layer); - paintedLayerData->mAssignedDisplayItems.SetCapacity(userData->mLastItemCount); + paintedLayerData->mAssignedDisplayItems.reserve(userData->mLastItemCount); NS_ASSERTION(FindIndexOfLayerIn(mNewChildLayers, layer) < 0, "Layer already in list???"); @@ -6152,7 +6155,7 @@ static void DebugPaintItem(DrawTarget& aDrawTarget, #endif /* static */ void -FrameLayerBuilder::RecomputeVisibilityForItems(nsTArray& aItems, +FrameLayerBuilder::RecomputeVisibilityForItems(std::vector& aItems, nsDisplayListBuilder *aBuilder, const nsIntRegion& aRegionToDraw, nsRect& aPreviousRectToDraw, @@ -6175,7 +6178,7 @@ FrameLayerBuilder::RecomputeVisibilityForItems(nsTArray& aI nsRect previousRectToDraw = aPreviousRectToDraw; aPreviousRectToDraw = visible.GetBounds(); - for (i = aItems.Length(); i > 0; --i) { + for (i = aItems.size(); i > 0; --i) { AssignedDisplayItem* cdi = &aItems[i - 1]; if (!cdi->mItem) { continue; @@ -6310,7 +6313,7 @@ UpdateOpacityNesting(int& aOpacityNesting, DisplayItemEntryType aType) } void -FrameLayerBuilder::PaintItems(nsTArray& aItems, +FrameLayerBuilder::PaintItems(std::vector& aItems, const nsIntRect& aRect, gfxContext *aContext, nsDisplayListBuilder* aBuilder, @@ -6337,7 +6340,7 @@ FrameLayerBuilder::PaintItems(nsTArray& aItems, ClipTracker clipTracker(aContext); - for (uint32_t i = 0; i < aItems.Length(); ++i) { + for (uint32_t i = 0; i < aItems.size(); ++i) { AssignedDisplayItem& cdi = aItems[i]; nsDisplayItem* item = cdi.mItem; diff --git a/layout/painting/FrameLayerBuilder.h b/layout/painting/FrameLayerBuilder.h index 6760a108fad9..39f8bde73d4e 100644 --- a/layout/painting/FrameLayerBuilder.h +++ b/layout/painting/FrameLayerBuilder.h @@ -665,7 +665,7 @@ protected: * PaintedLayer. */ - static void RecomputeVisibilityForItems(nsTArray& aItems, + static void RecomputeVisibilityForItems(std::vector& aItems, nsDisplayListBuilder* aBuilder, const nsIntRegion& aRegionToDraw, nsRect& aPreviousRectToDraw, @@ -674,7 +674,7 @@ protected: float aXScale, float aYScale); - void PaintItems(nsTArray& aItems, + void PaintItems(std::vector& aItems, const nsIntRect& aRect, gfxContext* aContext, nsDisplayListBuilder* aBuilder,