Bug 1624247 part 2: Rename flex item helper-struct from CachedMeasuringReflowResult to CachedBAxisMeasurement. r=TYLin
authorDaniel Holbert <dholbert@cs.stanford.edu>
Wed, 25 Mar 2020 04:52:02 +0000
changeset 520341 7d8eddd3ede1babf661c95a672d0188b4af221c0
parent 520340 782a1cdba0ae15750c7b6eae8957c0d1cb36a861
child 520342 a03ed46ab68a01d42aa752c425f389a633eb7f00
push id37248
push userbtara@mozilla.com
push dateWed, 25 Mar 2020 16:40:49 +0000
treeherdermozilla-central@c5112a7573ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTYLin
bugs1624247
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1624247 part 2: Rename flex item helper-struct from CachedMeasuringReflowResult to CachedBAxisMeasurement. r=TYLin This patch should not impact behavior; it is purely a rename. The "reflow result" naming is too generic for this struct, now that I'm planning to cache other results from flex item reflow (in later patches). This particular struct is caching block-axis measurements (a BSize and an ascent), so let's rename it to reflect that. Differential Revision: https://phabricator.services.mozilla.com/D67801
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsFlexContainerFrame.h
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -30,18 +30,17 @@ using namespace mozilla;
 using namespace mozilla::layout;
 
 // Convenience typedefs for helper classes that we forward-declare in .h file
 // (so that nsFlexContainerFrame methods can use them as parameters):
 using FlexItem = nsFlexContainerFrame::FlexItem;
 using FlexLine = nsFlexContainerFrame::FlexLine;
 using FlexboxAxisTracker = nsFlexContainerFrame::FlexboxAxisTracker;
 using StrutInfo = nsFlexContainerFrame::StrutInfo;
-using CachedMeasuringReflowResult =
-    nsFlexContainerFrame::CachedMeasuringReflowResult;
+using CachedBAxisMeasurement = nsFlexContainerFrame::CachedBAxisMeasurement;
 
 static mozilla::LazyLogModule gFlexContainerLog("FlexContainer");
 #define FLEX_LOG(...) \
   MOZ_LOG(gFlexContainerLog, LogLevel::Debug, (__VA_ARGS__));
 
 // XXXdholbert Some of this helper-stuff should be separated out into a general
 // "main/cross-axis utils" header, shared by grid & flexbox?
 // (Particularly when grid gets support for align-*/justify-* properties.)
@@ -1620,18 +1619,19 @@ void nsFlexContainerFrame::ResolveAutoFl
   }
 
   if (isMainMinSizeAuto) {
     aFlexItem.UpdateMainMinSize(resolvedMinSize);
   }
 }
 
 /**
- * A cached result for a measuring reflow. This cache prevents us from doing
- * exponential reflows in cases of deeply nested flex and scroll frames.
+ * A cached result for a flex item's block-axis measuring reflow. This cache
+ * prevents us from doing exponential reflows in cases of deeply nested flex
+ * and scroll frames.
  *
  * We store the cached value in the flex item's frame property table, for
  * simplicity.
  *
  * Right now, we cache the following as a "key", from the item's ReflowInput:
  *   - its ComputedSize
  *   - its min/max block size (in case its ComputedBSize is unconstrained)
  *   - its AvailableBSize
@@ -1659,17 +1659,17 @@ void nsFlexContainerFrame::ResolveAutoFl
  *    from the value in our Key.
  *
  * One particular case to consider (& need to be sure not to break when
  * changing this class): the flex item's computed BSize may change between
  * measuring reflows due to how the mIsFlexContainerMeasuringBSize flag affects
  * size computation (see bug 1336708). This is one reason we need to use the
  * computed BSize as part of the key.
  */
-class nsFlexContainerFrame::CachedMeasuringReflowResult {
+class nsFlexContainerFrame::CachedBAxisMeasurement {
   struct Key {
     LogicalSize mComputedSize;
     nscoord mComputedMinBSize;
     nscoord mComputedMaxBSize;
     nscoord mAvailableBSize;
 
     explicit Key(const ReflowInput& aRI)
         : mComputedSize(aRI.ComputedSize()),
@@ -1686,18 +1686,18 @@ class nsFlexContainerFrame::CachedMeasur
   };
 
   Key mKey;
 
   nscoord mBSize;
   nscoord mAscent;
 
  public:
-  CachedMeasuringReflowResult(const ReflowInput& aReflowInput,
-                              const ReflowOutput& aReflowOutput)
+  CachedBAxisMeasurement(const ReflowInput& aReflowInput,
+                         const ReflowOutput& aReflowOutput)
       : mKey(aReflowInput), mAscent(aReflowOutput.BlockStartAscent()) {
     // To get content-box bsize, we have to subtract off border & padding
     // (and floor at 0 in case the border/padding are too large):
     WritingMode itemWM = aReflowInput.GetWritingMode();
     nscoord borderBoxBSize = aReflowOutput.BSize(itemWM);
     mBSize = borderBoxBSize -
              aReflowInput.ComputedLogicalBorderPadding().BStartEnd(itemWM);
     mBSize = std::max(0, mBSize);
@@ -1713,29 +1713,29 @@ class nsFlexContainerFrame::CachedMeasur
   }
 
   nscoord BSize() const { return mBSize; }
 
   nscoord Ascent() const { return mAscent; }
 
   // Instances of this class are stored under this frame property, on
   // frames that are flex items:
-  NS_DECLARE_FRAME_PROPERTY_DELETABLE(Prop, CachedMeasuringReflowResult)
+  NS_DECLARE_FRAME_PROPERTY_DELETABLE(Prop, CachedBAxisMeasurement)
 };
 
 void nsFlexContainerFrame::MarkCachedFlexMeasurementsDirty(
     nsIFrame* aItemFrame) {
-  aItemFrame->RemoveProperty(CachedMeasuringReflowResult::Prop());
+  aItemFrame->RemoveProperty(CachedBAxisMeasurement::Prop());
 }
 
-const CachedMeasuringReflowResult&
+const CachedBAxisMeasurement&
 nsFlexContainerFrame::MeasureAscentAndBSizeForFlexItem(
     FlexItem& aItem, ReflowInput& aChildReflowInput) {
   auto* cachedResult =
-      aItem.Frame()->GetProperty(CachedMeasuringReflowResult::Prop());
+      aItem.Frame()->GetProperty(CachedBAxisMeasurement::Prop());
   if (cachedResult) {
     if (cachedResult->IsValidFor(aChildReflowInput)) {
       return *cachedResult;
     }
     FLEX_LOG("[perf] MeasureAscentAndBSizeForFlexItem rejected cached value");
   } else {
     FLEX_LOG(
         "[perf] MeasureAscentAndBSizeForFlexItem didn't have a cached value");
@@ -1768,22 +1768,21 @@ nsFlexContainerFrame::MeasureAscentAndBS
   FinishReflowChild(aItem.Frame(), PresContext(), childReflowOutput,
                     &aChildReflowInput, outerWM, dummyPosition,
                     dummyContainerSize, flags);
 
   // Update (or add) our cached measurement, so that we can hopefully skip this
   // measuring reflow the next time around:
   if (cachedResult) {
     *cachedResult =
-        CachedMeasuringReflowResult(aChildReflowInput, childReflowOutput);
+        CachedBAxisMeasurement(aChildReflowInput, childReflowOutput);
   } else {
     cachedResult =
-        new CachedMeasuringReflowResult(aChildReflowInput, childReflowOutput);
-    aItem.Frame()->SetProperty(CachedMeasuringReflowResult::Prop(),
-                               cachedResult);
+        new CachedBAxisMeasurement(aChildReflowInput, childReflowOutput);
+    aItem.Frame()->SetProperty(CachedBAxisMeasurement::Prop(), cachedResult);
   }
   return *cachedResult;
 }
 
 /* virtual */
 void nsFlexContainerFrame::MarkIntrinsicISizesDirty() {
   mCachedMinISize = NS_INTRINSIC_ISIZE_UNKNOWN;
   mCachedPrefISize = NS_INTRINSIC_ISIZE_UNKNOWN;
@@ -1813,21 +1812,21 @@ nscoord nsFlexContainerFrame::MeasureFle
   }
 
   if (aForceBResizeForMeasuringReflow) {
     childRIForMeasuringBSize.SetBResize(true);
     // Not 100% sure this is needed, but be conservative for now:
     childRIForMeasuringBSize.mFlags.mIsBResizeForPercentages = true;
   }
 
-  const CachedMeasuringReflowResult& reflowResult =
+  const CachedBAxisMeasurement& measurement =
       MeasureAscentAndBSizeForFlexItem(aFlexItem, childRIForMeasuringBSize);
 
-  aFlexItem.SetAscent(reflowResult.Ascent());
-  return reflowResult.BSize();
+  aFlexItem.SetAscent(measurement.Ascent());
+  return measurement.BSize();
 }
 
 FlexItem::FlexItem(ReflowInput& aFlexItemReflowInput, float aFlexGrow,
                    float aFlexShrink, nscoord aFlexBaseSize,
                    nscoord aMainMinSize, nscoord aMainMaxSize,
                    nscoord aTentativeCrossSize, nscoord aCrossMinSize,
                    nscoord aCrossMaxSize,
                    const FlexboxAxisTracker& aAxisTracker)
@@ -4017,25 +4016,25 @@ void nsFlexContainerFrame::SizeItemInCro
     // (Note: we know that the cross axis is the item's *block* axis -- if it
     // weren't, then we would've taken the early-return above.)
     aChildReflowInput.SetBResize(true);
     // Not 100% sure this is needed, but be conservative for now:
     aChildReflowInput.mFlags.mIsBResizeForPercentages = true;
   }
 
   // Potentially reflow the item, and get the sizing info.
-  const CachedMeasuringReflowResult& reflowResult =
+  const CachedBAxisMeasurement& measurement =
       MeasureAscentAndBSizeForFlexItem(aItem, aChildReflowInput);
 
   // Save the sizing info that we learned from this reflow
   // -----------------------------------------------------
 
   // Tentatively store the child's desired content-box cross-size.
-  aItem.SetCrossSize(reflowResult.BSize());
-  aItem.SetAscent(reflowResult.Ascent());
+  aItem.SetCrossSize(measurement.BSize());
+  aItem.SetAscent(measurement.Ascent());
 }
 
 void FlexLine::PositionItemsInCrossAxis(
     nscoord aLineStartPosition, const FlexboxAxisTracker& aAxisTracker) {
   SingleLineCrossAxisPositionTracker lineCrossAxisPosnTracker(aAxisTracker);
 
   for (FlexItem& item : Items()) {
     // First, stretch the item's cross size (if appropriate), and resolve any
--- a/layout/generic/nsFlexContainerFrame.h
+++ b/layout/generic/nsFlexContainerFrame.h
@@ -98,17 +98,17 @@ class nsFlexContainerFrame final : publi
   friend nsContainerFrame* NS_NewFlexContainerFrame(
       mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
 
   // Forward-decls of helper classes
   class FlexItem;
   class FlexLine;
   class FlexboxAxisTracker;
   struct StrutInfo;
-  class CachedMeasuringReflowResult;
+  class CachedBAxisMeasurement;
 
   // nsIFrame overrides
   void Init(nsIContent* aContent, nsContainerFrame* aParent,
             nsIFrame* aPrevInFlow) override;
 
   void BuildDisplayList(nsDisplayListBuilder* aBuilder,
                         const nsDisplayListSet& aLists) override;
 
@@ -329,23 +329,23 @@ class nsFlexContainerFrame final : publi
    * or moving the new item to a new line otherwise.
    */
   FlexItem* GenerateFlexItemForChild(FlexLine& aLine, nsIFrame* aChildFrame,
                                      const ReflowInput& aParentReflowInput,
                                      const FlexboxAxisTracker& aAxisTracker,
                                      bool aHasLineClampEllipsis);
 
   /**
-   * This method gets a cached measuring reflow for a flex item, or does it and
-   * caches it.
+   * This method looks up cached block-axis measurements for a flex item, or
+   * does a measuring reflow and caches those measurements.
    *
-   * This avoids exponential reflows, see the comment on
-   * CachedMeasuringReflowResult.
+   * This avoids exponential reflows - see the comment above the
+   * CachedBAxisMeasurement struct.
    */
-  const CachedMeasuringReflowResult& MeasureAscentAndBSizeForFlexItem(
+  const CachedBAxisMeasurement& MeasureAscentAndBSizeForFlexItem(
       FlexItem& aItem, ReflowInput& aChildReflowInput);
 
   /**
    * This method performs a "measuring" reflow to get the content BSize of
    * aFlexItem.Frame() (treating it as if it had a computed BSize of "auto"),
    * and returns the resulting BSize measurement.
    * (Helper for ResolveAutoFlexBasisAndMinSize().)
    */