Bug 1445230 - [css-grid] Use IntegerRange to make iterating over LineRange more ergonomic (idempotent change). r=dholbert
authorMats Palmgren <mats@mozilla.com>
Fri, 16 Mar 2018 12:11:38 +0100
changeset 408478 4558e9aeca365fe209b9ccbbf7cb4081e5903cee
parent 408477 023c4f7e7d7682b3c245490ba4df3de7a7b48c0a
child 408479 69c8d308183a4dfcc6152c752810e055e8c0ad6b
push id100952
push usermpalmgren@mozilla.com
push dateFri, 16 Mar 2018 11:11:50 +0000
treeherdermozilla-inbound@4558e9aeca36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1445230
milestone61.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 1445230 - [css-grid] Use IntegerRange to make iterating over LineRange more ergonomic (idempotent change). r=dholbert
layout/generic/nsGridContainerFrame.cpp
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -10,16 +10,17 @@
 
 #include <algorithm> // for std::stable_sort
 #include <functional>
 #include <limits>
 #include "gfxContext.h"
 #include "mozilla/CSSAlignUtils.h"
 #include "mozilla/CSSOrderAwareFrameIterator.h"
 #include "mozilla/dom/GridBinding.h"
+#include "mozilla/IntegerRange.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/PodOperations.h" // for PodZero
 #include "mozilla/Poison.h"
 #include "nsAbsoluteContainingBlock.h"
 #include "nsAlgorithm.h" // for clamped()
 #include "nsCSSAnonBoxes.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsDataHashtable.h"
@@ -424,16 +425,22 @@ struct nsGridContainerFrame::LineRange
     MOZ_ASSERT(mEnd != kAutoLine, "Extent is undefined for abs.pos. 'auto'");
     if (IsAuto()) {
       MOZ_ASSERT(mEnd >= 1 && mEnd < uint32_t(nsStyleGridLine::kMaxLine),
                  "invalid span");
       return mEnd;
     }
     return mEnd - mStart;
   }
+
+  /**
+   * Return an object suitable for iterating this range.
+   */
+  auto Range() const { return IntegerRange<uint32_t>(mStart, mEnd); }
+
   /**
    * Resolve this auto range to start at aStart, making it definite.
    * Precondition: this range IsAuto()
    */
   void ResolveAutoPosition(uint32_t aStart, uint32_t aExplicitGridOffset)
   {
     MOZ_ASSERT(IsAuto(), "Why call me?");
     mStart = aStart;
@@ -1247,19 +1254,17 @@ struct nsGridContainerFrame::Tracks
   template<TrackSizingPhase phase>
   nscoord CollectGrowable(nscoord              aAvailableSpace,
                           const LineRange&     aRange,
                           TrackSize::StateBits aSelector,
                           nsTArray<uint32_t>&  aGrowableTracks) const
   {
     MOZ_ASSERT(aAvailableSpace > 0, "why call me?");
     nscoord space = aAvailableSpace - mGridGap * (aRange.Extent() - 1);
-    const uint32_t start = aRange.mStart;
-    const uint32_t end = aRange.mEnd;
-    for (uint32_t i = start; i < end; ++i) {
+    for (auto i : aRange.Range()) {
       const TrackSize& sz = mSizes[i];
       space -= StartSizeInDistribution<phase>(sz);
       if (space <= 0) {
         return 0;
       }
       if (sz.mState & aSelector) {
         aGrowableTracks.AppendElement(i);
       }
@@ -3864,19 +3869,17 @@ nsGridContainerFrame::Tracks::CalculateS
   }
 }
 
 TrackSize::StateBits
 nsGridContainerFrame::Tracks::StateBitsForRange(const LineRange& aRange) const
 {
   MOZ_ASSERT(!aRange.IsAuto(), "must have a definite range");
   TrackSize::StateBits state = TrackSize::StateBits(0);
-  const uint32_t start = aRange.mStart;
-  const uint32_t end = aRange.mEnd;
-  for (uint32_t i = start; i < end; ++i) {
+  for (auto i : aRange.Range()) {
     state |= mSizes[i].mState;
   }
   return state;
 }
 
 bool
 nsGridContainerFrame::Tracks::ResolveIntrinsicSizeStep1(
   GridReflowInput&            aState,
@@ -4265,18 +4268,18 @@ nsGridContainerFrame::Tracks::GrowSizeFo
   bool needToUpdateSizes = false;
   InitializePlan<phase>(aPlan);
   for (; aIter != aIterEnd; ++aIter) {
     const Step2ItemData& item = *aIter;
     if (!(item.mState & aSelector)) {
       continue;
     }
     if (isMaxSizingPhase) {
-      for (auto j = item.mLineRange.mStart, end = item.mLineRange.mEnd; j < end; ++j) {
-        aPlan[j].mState |= TrackSize::eModified;
+      for (auto i : item.mLineRange.Range()) {
+        aPlan[i].mState |= TrackSize::eModified;
       }
     }
     nscoord space = item.SizeContributionForPhase<phase>();
     if (space <= 0) {
       continue;
     }
     aTracks.ClearAndRetainStorage();
     space = CollectGrowable<phase>(space, item.mLineRange, aSelector,
@@ -4367,17 +4370,17 @@ nsGridContainerFrame::Tracks::ResolveInt
         perSpanData[span].mStateBits |= state;
         CachedIntrinsicSizes cache;
         // Calculate data for "Automatic Minimum Size" clamping, if needed.
         bool needed = ((state & TrackSize::eIntrinsicMinSizing) ||
                        aConstraint == SizingConstraint::eNoConstraint) &&
                       (gridItem.mState[mAxis] & ItemState::eApplyAutoMinSize);
         if (needed && TrackSize::IsDefiniteMaxSizing(state)) {
           nscoord minSizeClamp = 0;
-          for (auto i = lineRange.mStart, end = lineRange.mEnd; i < end; ++i) {
+          for (auto i : lineRange.Range()) {
             auto maxCoord = aFunctions.MaxSizingFor(i);
             minSizeClamp += maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
           }
           minSizeClamp += mGridGap * (span - 1);
           cache.mMinSizeClamp = minSizeClamp;
           gridItem.mState[mAxis] |= ItemState::eClampMarginBoxMinSize;
         }
         // Collect the various grid item size contributions we need.
@@ -4516,17 +4519,17 @@ nsGridContainerFrame::Tracks::FindFrUnit
   const LineRange&            aRange,
   const nsTArray<uint32_t>&   aFlexTracks,
   const TrackSizingFunctions& aFunctions,
   nscoord                     aSpaceToFill) const
 {
   MOZ_ASSERT(aSpaceToFill > 0 && !aFlexTracks.IsEmpty());
   float flexFactorSum = 0.0f;
   nscoord leftOverSpace = aSpaceToFill;
-  for (uint32_t i = aRange.mStart, end = aRange.mEnd; i < end; ++i) {
+  for (auto i : aRange.Range()) {
     const TrackSize& sz = mSizes[i];
     if (sz.mState & TrackSize::eFlexMaxSizing) {
       flexFactorSum += aFunctions.MaxSizingFor(i).GetFlexFractionValue();
     } else {
       leftOverSpace -= sz.mBase;
       if (leftOverSpace <= 0) {
         return 0.0f;
       }
@@ -4608,17 +4611,17 @@ nsGridContainerFrame::Tracks::FindUsedFl
       if (spannedGaps > 0) {
         spaceToFill -= mGridGap * spannedGaps;
       }
       if (spaceToFill <= 0) {
         continue;
       }
       // ... and all its spanned tracks as input.
       nsTArray<uint32_t> itemFlexTracks;
-      for (uint32_t i = range.mStart, end = range.mEnd; i < end; ++i) {
+      for (auto i : range.Range()) {
         if (mSizes[i].mState & TrackSize::eFlexMaxSizing) {
           itemFlexTracks.AppendElement(i);
         }
       }
       float itemFr =
         FindFrUnitSize(range, itemFlexTracks, aFunctions, spaceToFill);
       fr = std::max(fr, itemFr);
     }