Bug 1581106 part 2 - Simplify LineNameMap ctor by deducing track clamping bounds instead of passing them as params (idempotent change). r=dholbert
authorMats Palmgren <mats@mozilla.com>
Mon, 30 Sep 2019 17:51:28 +0000
changeset 495708 9fd948f30837f9d2255bbd476558da227c0e5e44
parent 495707 75d66006c4a1c6679097fca7ab0d778d780a6001
child 495709 91d2317a3e6416a60737ef61fc834a20a62ec082
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1581106
milestone71.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 1581106 part 2 - Simplify LineNameMap ctor by deducing track clamping bounds instead of passing them as params (idempotent change). r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D46373
layout/generic/nsGridContainerFrame.cpp
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -1322,44 +1322,46 @@ struct nsGridContainerFrame::TrackSizing
  */
 class MOZ_STACK_CLASS nsGridContainerFrame::LineNameMap {
  public:
   /**
    * Create a LineNameMap.
    * @param aStylePosition the style for the grid container
    * @param aImplicitNamedAreas the implicit areas for the grid container
    * @param aGridTemplate is the grid-template-rows/columns data for this axis
-   * @param aClampMinLine/aClampMaxLine in a non-subgrid axis it's kMin/MaxLine;
-   *   in a subgrid axis it's its explicit grid bounds (all 1-based)
    * @param aParentLineNameMap the parent grid's map parallel to this map, or
    *                           null if this map isn't for a subgrid
    * @param aRange the subgrid's range in the parent grid, or null
    * @param aIsSameDirection true if our axis progresses in the same direction
    *                              in the subgrid and parent
    */
   LineNameMap(const nsStylePosition* aStylePosition,
               const ImplicitNamedAreas* aImplicitNamedAreas,
               const TrackSizingFunctions& aTracks,
-              int32_t aClampMinLine, int32_t aClampMaxLine,
               const LineNameMap* aParentLineNameMap, const LineRange* aRange,
               bool aIsSameDirection)
-      : mClampMinLine(aClampMinLine),
-        mClampMaxLine(aClampMaxLine),
-        mStylePosition(aStylePosition),
+      : mStylePosition(aStylePosition),
         mAreas(aImplicitNamedAreas),
         mTracks(aTracks),
         mRepeatAutoStart(aTracks.mRepeatAutoStart),
         mRepeatAutoEnd(aTracks.mRepeatAutoEnd),
         mRepeatEndDelta(aTracks.mRepeatEndDelta),
         mTemplateLinesEnd(aTracks.mExpandedLineNames.Length() +
                           mRepeatEndDelta),
         mParentLineNameMap(aParentLineNameMap),
         mRange(aRange),
         mIsSameDirection(aIsSameDirection),
         mHasRepeatAuto(aTracks.mHasRepeatAuto) {
+    if (MOZ_UNLIKELY(aRange)) { // subgrid case
+      mClampMinLine = 1;
+      mClampMaxLine = 1 + aRange->Extent();
+    } else {
+      mClampMinLine = kMinLine;
+      mClampMaxLine = kMaxLine;
+    }
     MOZ_ASSERT(mHasRepeatAuto || mRepeatEndDelta == 0);
     MOZ_ASSERT(!mHasRepeatAuto ||
                (mTracks.mExpandedLineNames.Length() >= 2 &&
                 mRepeatAutoStart <= mTracks.mExpandedLineNames.Length()));
   }
 
   /**
    * Find the aNth occurrence of aName, searching forward if aNth is positive,
@@ -1461,18 +1463,18 @@ class MOZ_STACK_CLASS nsGridContainerFra
         return true;
       }
       map = map->mParentLineNameMap;
     } while (map);
     return false;
   }
 
   // The min/max line number (1-based) for clamping.
-  const int32_t mClampMinLine;
-  const int32_t mClampMaxLine;
+  int32_t mClampMinLine;
+  int32_t mClampMaxLine;
 
  private:
   // Return true if this map represents a subgridded axis.
   bool IsSubgridded() const { return mParentLineNameMap != nullptr; }
 
   /**
    * @see FindNamedLine, this function searches forward.
    */
@@ -4069,74 +4071,64 @@ void nsGridContainerFrame::Grid::PlaceGr
   // by 'grid-template-areas' and the 'grid-template-rows'/'-columns', plus one.
   // Also initialize the Implicit Grid (mGridCol[Row]End) to the same values.
   // Note that this is for a grid with a 1,1 origin.  We'll change that
   // to a 0,0 based grid after placing definite lines.
   const nsStylePosition* const gridStyle = aState.mGridStyle;
   const auto* areas = gridStyle->mGridTemplateAreas.IsNone()
                           ? nullptr
                           : &*gridStyle->mGridTemplateAreas.AsAreas();
-  int32_t clampMinColLine = kMinLine;
-  int32_t clampMaxColLine = kMaxLine;
   const LineNameMap* parentLineNameMap = nullptr;
   const LineRange* subgridRange = nullptr;
   bool subgridAxisIsSameDirection = true;
   if (!aState.mFrame->IsColSubgrid()) {
     aState.mColFunctions.InitRepeatTracks(
         gridStyle->mColumnGap, aSizes.mMin.ISize(aState.mWM),
         aSizes.mSize.ISize(aState.mWM), aSizes.mMax.ISize(aState.mWM));
     uint32_t areaCols = areas ? areas->width + 1 : 1;
     mExplicitGridColEnd = aState.mColFunctions.ComputeExplicitGridEnd(areaCols);
   } else {
     const auto* subgrid = aState.mFrame->GetProperty(Subgrid::Prop());
     subgridRange = &subgrid->SubgridCols();
     uint32_t extent = subgridRange->Extent();
     mExplicitGridColEnd = extent + 1;  // the grid is 1-based at this point
-    clampMinColLine = 1;
-    clampMaxColLine = mExplicitGridColEnd;
     parentLineNameMap =
         ParentLineMapForAxis(subgrid->mIsOrthogonal, eLogicalAxisInline);
     auto parentWM =
         aState.mFrame->ParentGridContainerForSubgrid()->GetWritingMode();
     subgridAxisIsSameDirection =
         aState.mWM.ParallelAxisStartsOnSameSide(eLogicalAxisInline, parentWM);
   }
   mGridColEnd = mExplicitGridColEnd;
   LineNameMap colLineNameMap(gridStyle, mAreas, aState.mColFunctions,
-                             clampMinColLine, clampMaxColLine,
                              parentLineNameMap, subgridRange,
                              subgridAxisIsSameDirection);
 
-  int32_t clampMinRowLine = kMinLine;
-  int32_t clampMaxRowLine = kMaxLine;
   if (!aState.mFrame->IsRowSubgrid()) {
     aState.mRowFunctions.InitRepeatTracks(
         gridStyle->mRowGap, aSizes.mMin.BSize(aState.mWM),
         aSizes.mSize.BSize(aState.mWM), aSizes.mMax.BSize(aState.mWM));
     uint32_t areaRows = areas ? areas->strings.Length() + 1 : 1;
     mExplicitGridRowEnd = aState.mRowFunctions.ComputeExplicitGridEnd(areaRows);
     parentLineNameMap = nullptr;
     subgridRange = nullptr;
   } else {
     const auto* subgrid = aState.mFrame->GetProperty(Subgrid::Prop());
     subgridRange = &subgrid->SubgridRows();
     uint32_t extent = subgridRange->Extent();
     mExplicitGridRowEnd = extent + 1;  // the grid is 1-based at this point
-    clampMinRowLine = 1;
-    clampMaxRowLine = mExplicitGridRowEnd;
     parentLineNameMap =
         ParentLineMapForAxis(subgrid->mIsOrthogonal, eLogicalAxisBlock);
     auto parentWM =
         aState.mFrame->ParentGridContainerForSubgrid()->GetWritingMode();
     subgridAxisIsSameDirection =
         aState.mWM.ParallelAxisStartsOnSameSide(eLogicalAxisBlock, parentWM);
   }
   mGridRowEnd = mExplicitGridRowEnd;
   LineNameMap rowLineNameMap(gridStyle, mAreas, aState.mRowFunctions,
-                             clampMinRowLine, clampMaxRowLine,
                              parentLineNameMap, subgridRange,
                              subgridAxisIsSameDirection);
 
   const bool isSubgridOrItemInSubgrid =
       aState.mFrame->IsSubgrid() || !!mParentGrid;
   auto SetSubgridChildEdgeBits =
       [this, isSubgridOrItemInSubgrid](GridItemInfo& aItem) -> void {
     if (isSubgridOrItemInSubgrid) {
@@ -4184,18 +4176,16 @@ void nsGridContainerFrame::Grid::PlaceGr
   mExplicitGridOffsetCol = 1 - minCol;  // minCol/Row is always <= 1, see above
   mExplicitGridOffsetRow = 1 - minRow;
   aState.mColFunctions.mExplicitGridOffset = mExplicitGridOffsetCol;
   aState.mRowFunctions.mExplicitGridOffset = mExplicitGridOffsetRow;
   const int32_t offsetToColZero = int32_t(mExplicitGridOffsetCol) - 1;
   const int32_t offsetToRowZero = int32_t(mExplicitGridOffsetRow) - 1;
   mGridColEnd += offsetToColZero;
   mGridRowEnd += offsetToRowZero;
-  clampMaxColLine += offsetToColZero;
-  clampMaxRowLine += offsetToRowZero;
   aState.mIter.Reset();
   for (; !aState.mIter.AtEnd(); aState.mIter.Next()) {
     auto& item = aState.mGridItems[aState.mIter.ItemIndex()];
     GridArea& area = item.mArea;
     if (area.mCols.IsDefinite()) {
       area.mCols.mStart = area.mCols.mUntranslatedStart + offsetToColZero;
       area.mCols.mEnd = area.mCols.mUntranslatedEnd + offsetToColZero;
     }
@@ -4215,16 +4205,18 @@ void nsGridContainerFrame::Grid::PlaceGr
   }
 
   // http://dev.w3.org/csswg/css-grid/#auto-placement-algo
   // Step 1, place 'auto' items that have one definite position -
   // definite row (column) for grid-auto-flow:row (column).
   auto flowStyle = gridStyle->mGridAutoFlow;
   const bool isRowOrder = (flowStyle & NS_STYLE_GRID_AUTO_FLOW_ROW);
   const bool isSparse = !(flowStyle & NS_STYLE_GRID_AUTO_FLOW_DENSE);
+  uint32_t clampMaxColLine = colLineNameMap.mClampMaxLine + offsetToColZero;
+  uint32_t clampMaxRowLine = rowLineNameMap.mClampMaxLine + offsetToRowZero;
   // We need 1 cursor per row (or column) if placement is sparse.
   {
     Maybe<nsDataHashtable<nsUint32HashKey, uint32_t>> cursors;
     if (isSparse) {
       cursors.emplace();
     }
     auto placeAutoMinorFunc =
         isRowOrder ? &Grid::PlaceAutoCol : &Grid::PlaceAutoRow;