Bug 1454822 part 2: Cache the results of nsFlexContainerFrame::GetMinISize/GetPrefISize. r?mats
Assuming we call MarkIntrinsicISizesDirty in the appropriate scenarios, this
patch shouldn't change behavior - it just caches these values so we don't
needlessly recalculate them.
MozReview-Commit-ID: 8QY4AZJXshy
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -1739,16 +1739,19 @@ nsFlexContainerFrame::MeasureAscentAndBS
aItem.Frame()->SetProperty(CachedFlexMeasuringReflow(), result);
return *result;
}
/* virtual */ void
nsFlexContainerFrame::MarkIntrinsicISizesDirty()
{
+ mCachedMinISize = NS_INTRINSIC_WIDTH_UNKNOWN;
+ mCachedPrefISize = NS_INTRINSIC_WIDTH_UNKNOWN;
+
for (nsIFrame* childFrame : mFrames) {
childFrame->DeleteProperty(CachedFlexMeasuringReflow());
}
nsContainerFrame::MarkIntrinsicISizesDirty();
}
nscoord
nsFlexContainerFrame::
@@ -5113,24 +5116,28 @@ nsFlexContainerFrame::IntrinsicISize(gfx
}
return containerISize;
}
/* virtual */ nscoord
nsFlexContainerFrame::GetMinISize(gfxContext* aRenderingContext)
{
- nscoord minISize = 0;
- DISPLAY_MIN_WIDTH(this, minISize);
-
- minISize = IntrinsicISize(aRenderingContext, nsLayoutUtils::MIN_ISIZE);
- return minISize;
+ DISPLAY_MIN_WIDTH(this, mCachedMinISize);
+ if (mCachedMinISize == NS_INTRINSIC_WIDTH_UNKNOWN) {
+ mCachedMinISize = IntrinsicISize(aRenderingContext,
+ nsLayoutUtils::MIN_ISIZE);
+ }
+
+ return mCachedMinISize;
}
/* virtual */ nscoord
nsFlexContainerFrame::GetPrefISize(gfxContext* aRenderingContext)
{
- nscoord prefISize = 0;
- DISPLAY_PREF_WIDTH(this, prefISize);
-
- prefISize = IntrinsicISize(aRenderingContext, nsLayoutUtils::PREF_ISIZE);
- return prefISize;
+ DISPLAY_PREF_WIDTH(this, mCachedPrefISize);
+ if (mCachedPrefISize == NS_INTRINSIC_WIDTH_UNKNOWN) {
+ mCachedPrefISize = IntrinsicISize(aRenderingContext,
+ nsLayoutUtils::PREF_ISIZE);
+ }
+
+ return mCachedPrefISize;
}
--- a/layout/generic/nsFlexContainerFrame.h
+++ b/layout/generic/nsFlexContainerFrame.h
@@ -224,16 +224,18 @@ public:
*/
static bool IsUsedFlexBasisContent(const nsStyleCoord* aFlexBasis,
const nsStyleCoord* aMainSize);
protected:
// Protected constructor & destructor
explicit nsFlexContainerFrame(ComputedStyle* aStyle)
: nsContainerFrame(aStyle, kClassID)
+ , mCachedMinISize(NS_INTRINSIC_WIDTH_UNKNOWN)
+ , mCachedPrefISize(NS_INTRINSIC_WIDTH_UNKNOWN)
, mBaselineFromLastReflow(NS_INTRINSIC_WIDTH_UNKNOWN)
, mLastBaselineFromLastReflow(NS_INTRINSIC_WIDTH_UNKNOWN)
{}
virtual ~nsFlexContainerFrame();
/*
* This method does the bulk of the flex layout, implementing the algorithm
@@ -437,14 +439,20 @@ protected:
const nsSize& aContainerSize);
/**
* Helper for GetMinISize / GetPrefISize.
*/
nscoord IntrinsicISize(gfxContext* aRenderingContext,
nsLayoutUtils::IntrinsicISizeType aType);
+ /**
+ * Cached values to optimize GetMinISize/GetPrefISize.
+ */
+ nscoord mCachedMinISize;
+ nscoord mCachedPrefISize;
+
nscoord mBaselineFromLastReflow;
// Note: the last baseline is a distance from our border-box end edge.
nscoord mLastBaselineFromLastReflow;
};
#endif /* nsFlexContainerFrame_h___ */