Bug 1425599 part 3 - [css-grid] Factor out most of the max-sizing parts of the track sizing for spanned items to a templated method (idempotent change). r=dholbert a=jcristau
authorMats Palmgren <mats@mozilla.com>
Thu, 15 Mar 2018 22:41:24 +0100
changeset 462717 2405110bef04d0ba709c8e96a2a6d890986a1293
parent 462716 934d0c726031ac7938b12414b56bc7c7bd340d01
child 462718 a2d9cdb47e6257ac02696f6ce0a9432c6c485c39
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, jcristau
bugs1425599
milestone60.0
Bug 1425599 part 3 - [css-grid] Factor out most of the max-sizing parts of the track sizing for spanned items to a templated method (idempotent change). r=dholbert a=jcristau
layout/generic/nsGridContainerFrame.cpp
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -1174,26 +1174,36 @@ struct nsGridContainerFrame::Tracks
         case TrackSizingPhase::eMaxContentMinimums:
         case TrackSizingPhase::eMaxContentMaximums:
           return mMaxContentContribution;
       }
       MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected phase");
     }
   };
 
-  // Helper method for ResolveIntrinsicSize.
+  // Helper methods for ResolveIntrinsicSize.
   template<TrackSizingPhase phase>
   bool GrowBaseForSpanningItems(const nsTArray<Step2ItemData>& aItemData,
                                 nsTArray<uint32_t>& aTracks,
                                 nsTArray<TrackSize>& aPlan,
                                 nsTArray<TrackSize>& aItemPlan,
                                 TrackSize::StateBits aSelector,
                                 uint32_t aStartIndex,
                                 uint32_t aEndIndex);
-
+  template<TrackSizingPhase phase>
+  bool GrowLimitForSpanningItems(const nsTArray<Step2ItemData>& aItemData,
+                                 nsTArray<uint32_t>& aTracks,
+                                 const nsTArray<TrackSize>& aSizes,
+                                 nsTArray<TrackSize>& aPlan,
+                                 nsTArray<TrackSize>& aItemPlan,
+                                 TrackSize::StateBits aSelector,
+                                 const TrackSizingFunctions& aFunctions,
+                                 nscoord aPercentageBasis,
+                                 uint32_t aStartIndex,
+                                 uint32_t aEndIndex);
   /**
    * Resolve Intrinsic Track Sizes.
    * http://dev.w3.org/csswg/css-grid/#algo-content
    */
   void ResolveIntrinsicSize(GridReflowInput&            aState,
                             nsTArray<GridItemInfo>&     aGridItems,
                             const TrackSizingFunctions& aFunctions,
                             LineRange GridArea::*       aRange,
@@ -4244,16 +4254,53 @@ nsGridContainerFrame::Tracks::GrowBaseFo
     }
   }
   if (updatedBase) {
     CopyPlanToBase(aPlan);
   }
   return updatedBase;
 }
 
+template<nsGridContainerFrame::Tracks::TrackSizingPhase phase>
+bool
+nsGridContainerFrame::Tracks::GrowLimitForSpanningItems(
+  const nsTArray<Step2ItemData>& aItemData,
+  nsTArray<uint32_t>& aTracks,
+  const nsTArray<TrackSize>& aSizes,
+  nsTArray<TrackSize>& aPlan,
+  nsTArray<TrackSize>& aItemPlan,
+  TrackSize::StateBits aSelector,
+  const TrackSizingFunctions& aFunctions,
+  nscoord aPercentageBasis,
+  uint32_t aStartIndex,
+  uint32_t aEndIndex)
+{
+  ResetBasePlan(aPlan, aSizes);
+  for (uint32_t i = aStartIndex; i < aEndIndex; ++i) {
+    const Step2ItemData& item = aItemData[i];
+    if (!(item.mState & aSelector)) {
+      continue;
+    }
+    for (auto j = item.mLineRange.mStart, end = item.mLineRange.mEnd; j < end; ++j) {
+      aPlan[j].mState |= TrackSize::eModified;
+    }
+    nscoord space = item.SizeContributionForPhase(phase);
+    if (space > 0) {
+      aTracks.ClearAndRetainStorage();
+      space = CollectGrowable(space, aSizes, item.mLineRange, aSelector,
+                              aTracks);
+      if (space > 0) {
+        DistributeToTrackLimits(space, aSizes, aPlan, aItemPlan, aTracks,
+                                aFunctions, aPercentageBasis);
+      }
+    }
+  }
+  return true;
+}
+
 void
 nsGridContainerFrame::Tracks::ResolveIntrinsicSize(
   GridReflowInput&            aState,
   nsTArray<GridItemInfo>&     aGridItems,
   const TrackSizingFunctions& aFunctions,
   LineRange GridArea::*       aRange,
   nscoord                     aPercentageBasis,
   SizingConstraint            aConstraint)
@@ -4433,76 +4480,44 @@ nsGridContainerFrame::Tracks::ResolveInt
           if (sz.mLimit == NS_UNCONSTRAINEDSIZE) {
             // use mBase as the planned limit
           } else {
             sz.mBase = sz.mLimit;
           }
         }
 
         // Step 2.5 MinSize to intrinsic max-sizing.
-        ResetBasePlan(plan, limits);
-        for (i = spanGroupStartIndex; i < spanGroupEndIndex; ++i) {
-          Step2ItemData& item = step2Items[i];
-          if (!(item.mState & TrackSize::eIntrinsicMaxSizing)) {
-            continue;
-          }
-          for (auto j = item.mLineRange.mStart, end = item.mLineRange.mEnd; j < end; ++j) {
-            plan[j].mState |= TrackSize::eModified;
-          }
-          nscoord space = item.mMinSize;
-          if (space > 0) {
-            tracks.ClearAndRetainStorage();
-            space = CollectGrowable(space, limits, item.mLineRange,
-                                    TrackSize::eIntrinsicMaxSizing,
-                                    tracks);
-            if (space > 0) {
-              DistributeToTrackLimits(space, limits, plan, itemPlan, tracks, aFunctions,
-                                      aPercentageBasis);
-            }
-          }
-        }
+        GrowLimitForSpanningItems<TrackSizingPhase::eIntrinsicMaximums>(
+          step2Items, tracks, limits, plan, itemPlan, TrackSize::eIntrinsicMaxSizing,
+          aFunctions, aPercentageBasis, spanGroupStartIndex, spanGroupEndIndex);
+
         for (size_t j = 0, len = mSizes.Length(); j < len; ++j) {
           TrackSize& sz = itemPlan[j];
           sz.mState &= ~(TrackSize::eFrozen | TrackSize::eSkipGrowUnlimited);
           if (plan[j].mState & TrackSize::eModified) {
             limits[j].mBase = plan[j].mBase;
             mSizes[j].mLimit = plan[j].mBase;
             if (limits[j].mLimit != NS_UNCONSTRAINEDSIZE) {
               limits[j].mLimit = limits[j].mBase;
             }
           }
           plan[j].mState &= ~(TrackSize::eModified);
         }
 
         if (stateBitsPerSpan[span] & TrackSize::eAutoOrMaxContentMaxSizing) {
           // Step 2.6 MaxContentContribution to max-content max-sizing.
-          ResetBasePlan(plan, limits);
-          for (i = spanGroupStartIndex; i < spanGroupEndIndex; ++i) {
-            Step2ItemData& item = step2Items[i];
-            if (!(item.mState & TrackSize::eAutoOrMaxContentMaxSizing)) {
-              continue;
-            }
-          for (auto j = item.mLineRange.mStart, end = item.mLineRange.mEnd; j < end; ++j) {
-            plan[j].mState |= TrackSize::eModified;
-          }
-            nscoord space = item.mMaxContentContribution;
-            if (space > 0) {
-              tracks.ClearAndRetainStorage();
-              space = CollectGrowable(space, limits, item.mLineRange,
-                                      TrackSize::eAutoOrMaxContentMaxSizing,
-                                      tracks);
-              if (space > 0) {
-                DistributeToTrackLimits(space, limits, plan, itemPlan, tracks, aFunctions,
-                                        aPercentageBasis);
-              }
-            }
-          }
+          GrowLimitForSpanningItems<TrackSizingPhase::eMaxContentMaximums>(
+            step2Items, tracks, limits, plan, itemPlan, TrackSize::eAutoOrMaxContentMaxSizing,
+            aFunctions, aPercentageBasis, spanGroupStartIndex, spanGroupEndIndex);
+          
         }
         CopyPlanToLimit(plan);
       }
+
+      i = spanGroupEndIndex;
     }
   }
 
   // Step 3.
   for (TrackSize& sz : mSizes) {
     if (sz.mLimit == NS_UNCONSTRAINEDSIZE) {
       sz.mLimit = sz.mBase;
     }