Unverified Commit 69080e07 authored by Ferhat's avatar Ferhat Committed by GitHub

[Perf/codesize] Reduce constraint member reads during layout (#51418)

parent 9228b87e
......@@ -668,6 +668,7 @@ class _RenderCupertinoAlert extends RenderBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final bool hasDivider = contentSection.getMaxIntrinsicHeight(constraints.maxWidth) > 0.0
&& actionsSection.getMaxIntrinsicHeight(constraints.maxWidth) > 0.0;
final double dividerThickness = hasDivider ? _dividerThickness : 0.0;
......
......@@ -1540,6 +1540,7 @@ class _RenderCupertinoDialogActions extends RenderBox
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (_isSingleButtonRow(dialogWidth)) {
if (childCount == 1) {
// We have 1 button. Our size is the width of the dialog and the height
......
......@@ -104,6 +104,7 @@ class _RenderCupertinoSliverRefresh extends RenderSliver
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// Only pulling to refresh from the top is currently supported.
assert(constraints.axisDirection == AxisDirection.down);
assert(constraints.growthDirection == GrowthDirection.forward);
......
......@@ -628,6 +628,7 @@ class _RenderSegmentedControl<T> extends RenderBox
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
double maxHeight = _kMinSegmentedControlHeight;
double childWidth = constraints.minWidth / childCount;
......
......@@ -828,6 +828,7 @@ class _RenderSegmentedControl<T> extends RenderBox
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
double childWidth = (constraints.minWidth - totalSeparatorWidth) / childCount;
double maxHeight = _kMinSegmentedControlHeight;
......
......@@ -159,6 +159,7 @@ class _ToolbarRenderBox extends RenderShiftedBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
size = constraints.biggest;
if (child == null) {
......
......@@ -1346,6 +1346,7 @@ class _RenderAppBarTitleBox extends RenderAligningShiftedBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final BoxConstraints innerConstraints = constraints.copyWith(maxHeight: double.infinity);
child.layout(innerConstraints, parentUsesSize: true);
size = constraints.constrain(child.size);
......
......@@ -509,6 +509,7 @@ class _RenderInputPadding extends RenderShiftedBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
child.layout(constraints, parentUsesSize: true);
final double height = math.max(child.size.width, minSize.width);
......
......@@ -582,6 +582,7 @@ class _RenderChildOverflowBox extends RenderAligningShiftedBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
child.layout(const BoxConstraints(), parentUsesSize: true);
size = Size(
......
......@@ -1247,6 +1247,7 @@ class _RenderDecoration extends RenderBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_labelTransform = null;
final _RenderDecorationLayout layout = _layout(constraints);
......
......@@ -1328,6 +1328,7 @@ class _RenderListTile extends RenderBox {
// https://material.io/design/components/lists.html#specs
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final bool hasLeading = leading != null;
final bool hasSubtitle = subtitle != null;
final bool hasTrailing = trailing != null;
......
......@@ -170,7 +170,7 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
void performLayout() {
_lastValue = _controller.value;
_hasVisualOverflow = false;
final BoxConstraints constraints = this.constraints;
if (child == null || constraints.isTight) {
_controller.stop();
size = _sizeTween.begin = _sizeTween.end = constraints.smallest;
......
......@@ -1743,6 +1743,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
}
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
_caretPrototype = _getCaretPrototype;
_selectionRects = null;
......
......@@ -636,6 +636,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
@override
void performLayout() {
assert(_debugHasNecessaryDirections);
final BoxConstraints constraints = this.constraints;
// Determine used flex factor, size inflexible items, calculate free space.
int totalFlex = 0;
int totalChildren = 0;
......
......@@ -279,6 +279,7 @@ class RenderFlow extends RenderBox
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
size = _getSize(constraints);
int i = 0;
_randomAccessChildren.clear();
......
......@@ -63,6 +63,7 @@ class RenderListBody extends RenderBox
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
assert(() {
switch (mainAxis) {
case Axis.horizontal:
......
......@@ -575,6 +575,7 @@ class RenderParagraph extends RenderBox
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_layoutChildren(constraints);
_layoutTextWithConstraints(constraints);
_setParentData();
......
......@@ -260,6 +260,7 @@ class RenderConstrainedBox extends RenderProxyBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
child.layout(_additionalConstraints.enforce(constraints), parentUsesSize: true);
size = child.size;
......@@ -351,6 +352,7 @@ class RenderLimitedBox extends RenderProxyBox {
@override
void performLayout() {
if (child != null) {
final BoxConstraints constraints = this.constraints;
child.layout(_limitConstraints(constraints), parentUsesSize: true);
size = constraints.constrain(child.size);
} else {
......
......@@ -193,6 +193,7 @@ class RenderPadding extends RenderShiftedBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_resolve();
assert(_resolvedPadding != null);
if (child == null) {
......@@ -385,6 +386,7 @@ class RenderPositionedBox extends RenderAligningShiftedBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final bool shrinkWrapWidth = _widthFactor != null || constraints.maxWidth == double.infinity;
final bool shrinkWrapHeight = _heightFactor != null || constraints.maxHeight == double.infinity;
......@@ -649,6 +651,7 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
// Let the child lay itself out at it's "natural" size, but if
// constrainedAxis is non-null, keep any constraints on that axis.
......@@ -1183,6 +1186,7 @@ class RenderBaseline extends RenderShiftedBox {
@override
void performLayout() {
if (child != null) {
final BoxConstraints constraints = this.constraints;
child.layout(constraints.loosen(), parentUsesSize: true);
final double childBaseline = child.getDistanceToBaseline(baselineType);
final double actualBaseline = baseline;
......
......@@ -1813,6 +1813,7 @@ class RenderSliverToBoxAdapter extends RenderSliverSingleBoxAdapter {
geometry = SliverGeometry.zero;
return;
}
final SliverConstraints constraints = this.constraints;
child.layout(constraints.asBoxConstraints(), parentUsesSize: true);
double childExtent;
switch (constraints.axis) {
......
......@@ -87,6 +87,7 @@ class RenderSliverFillRemainingWithScrollable extends RenderSliverSingleBoxAdapt
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// TODO(Piinks): This may fill too much space for NestedScrollView, https://github.com/flutter/flutter/issues/46028
final double extent = constraints.remainingPaintExtent - math.min(constraints.overlap, 0.0);
......@@ -137,6 +138,7 @@ class RenderSliverFillRemaining extends RenderSliverSingleBoxAdapter {
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// The remaining space in the viewportMainAxisExtent. Can be <= 0 if we have
// scrolled beyond the extent of the screen.
double extent = constraints.viewportMainAxisExtent - constraints.precedingScrollExtent;
......@@ -209,6 +211,7 @@ class RenderSliverFillRemainingAndOverscroll extends RenderSliverSingleBoxAdapte
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// The remaining space in the viewportMainAxisExtent. Can be <= 0 if we have
// scrolled beyond the extent of the screen.
double extent = constraints.viewportMainAxisExtent - constraints.precedingScrollExtent;
......
......@@ -164,6 +164,7 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
childManager.didStartLayout();
childManager.setDidUnderflow(false);
......
......@@ -511,6 +511,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
childManager.didStartLayout();
childManager.setDidUnderflow(false);
......
......@@ -44,6 +44,7 @@ class RenderSliverList extends RenderSliverMultiBoxAdaptor {
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
childManager.didStartLayout();
childManager.setDidUnderflow(false);
......
......@@ -118,6 +118,7 @@ abstract class RenderSliverEdgeInsetsPadding extends RenderSliver with RenderObj
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
assert(resolvedPadding != null);
final double beforePadding = this.beforePadding;
final double afterPadding = this.afterPadding;
......
......@@ -331,6 +331,7 @@ abstract class RenderSliverScrollingPersistentHeader extends RenderSliverPersist
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
layoutChild(constraints.scrollOffset, maxExtent);
final double paintExtent = maxExtent - constraints.scrollOffset;
......@@ -369,6 +370,7 @@ abstract class RenderSliverPinnedPersistentHeader extends RenderSliverPersistent
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
final bool overlapsContent = constraints.overlap > 0.0;
excludeFromSemanticsScrolling = overlapsContent || (constraints.scrollOffset > maxExtent - minExtent);
......@@ -552,6 +554,7 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
if (_lastActualScrollOffset != null && // We've laid out at least once to get an initial position, and either
((constraints.scrollOffset < _lastActualScrollOffset) || // we are scrolling back, so should reveal, or
......
......@@ -517,6 +517,7 @@ class RenderStack extends RenderBox
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_resolve();
assert(_resolvedAlignment != null);
_hasVisualOverflow = false;
......
......@@ -992,6 +992,7 @@ class RenderTable extends RenderBox {
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final int rows = this.rows;
final int columns = this.columns;
assert(_children.length == rows * columns);
......
......@@ -1699,6 +1699,7 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (firstChild == null) {
switch (axis) {
case Axis.vertical:
......
......@@ -565,6 +565,7 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
assert(_debugHasNecessaryDirections);
_hasVisualOverflow = false;
RenderBox child = firstChild;
......
......@@ -238,6 +238,7 @@ class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<Ren
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
layoutAndBuildChild();
if (child != null) {
child.layout(constraints, parentUsesSize: true);
......
......@@ -505,6 +505,7 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child == null) {
size = constraints.smallest;
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment