Skip to content

Remove redundant assignment of geometry#151821

Merged
auto-submit[bot] merged 3 commits intoflutter:masterfrom
hgraceb:master
Jul 17, 2024
Merged

Remove redundant assignment of geometry#151821
auto-submit[bot] merged 3 commits intoflutter:masterfrom
hgraceb:master

Conversation

@hgraceb
Copy link
Copy Markdown
Member

@hgraceb hgraceb commented Jul 16, 2024

Remove redundant assignment of geometry.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Jul 16, 2024
Copy link
Copy Markdown
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

paintExtent: clampDouble(paintExtent, 0.0, constraints.remainingPaintExtent),
maxPaintExtent: maxExtent,
hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity.
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to future archaeologists: This code is redundant because updateGeometry called below also calculates and assigns geometry.

Comment on lines 366 to 368
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
layoutChild(constraints.scrollOffset, maxExtent);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: This could really just be simplified without the local variables:

Suggested change
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
layoutChild(constraints.scrollOffset, maxExtent);
layoutChild(constraints.scrollOffset, maxExtent);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a nice change.

from: 0.0,
to: maxExtent,
);
final double cacheExtent = calculateCacheOffset(constraints, from: 0.0, to: maxExtent);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it. Alouthgh In my opinion, it is most applicable to the second description:

but prefer going over if breaking the line would make it less readable, or if it would make the line less consistent with other nearby lines.

abstract class RenderSliverPersistentHeader extends RenderSliver with RenderObjectWithChildMixin<RenderBox>, RenderSliverHelpers {
  //                                                                                                                             ^ 130 chars 
  // ......

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    // ......
    properties.add(DoubleProperty.lazy('child position', () => childMainAxisPosition(child!)));
    //                                                                                        ^ 95 chars 
  }
}

abstract class RenderSliverScrollingPersistentHeader extends RenderSliverPersistentHeader {
  //                                                                                      ^ 91 chars 
  RenderSliverScrollingPersistentHeader({
    super.child,
    super.stretchConfiguration,
  });

  double? _childPosition;

  @protected
  double updateGeometry() {
    double stretchOffset = 0.0;
    if (stretchConfiguration != null) {
      stretchOffset += constraints.overlap.abs();
    }
    final double maxExtent = this.maxExtent;
    final double paintExtent = maxExtent - constraints.scrollOffset;
    final double cacheExtent = calculateCacheOffset(constraints, from: 0.0, to: maxExtent);
    //                                                                                    ^ 91 chars

    geometry = SliverGeometry(
      cacheExtent: cacheExtent,
      scrollExtent: maxExtent,
      paintOrigin: math.min(constraints.overlap, 0.0),
      paintExtent: clampDouble(paintExtent, 0.0, constraints.remainingPaintExtent),
      //                                                                          ^ 83 chars
      maxPaintExtent: maxExtent + stretchOffset,
      hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity.
      //                                                                                    ^ 93 chars
    );
    return stretchOffset > 0 ? 0.0 : math.min(0.0, paintExtent - childExtent);
  }

  @override
  void performLayout() {
    layoutChild(constraints.scrollOffset, maxExtent);
    _childPosition = updateGeometry();
  }

  @override
  double childMainAxisPosition(RenderBox child) {
    assert(child == this.child);
    assert(_childPosition != null);
    return _childPosition!;
  }
}

abstract class RenderSliverPinnedPersistentHeader extends RenderSliverPersistentHeader {
  //                                                                                   ^ 88 chars 
  // ......
}

@goderbauer goderbauer requested a review from Piinks July 17, 2024 09:50
@goderbauer
Copy link
Copy Markdown
Member

@hgraceb You'll also have to get a test exemption for this change per the bot message above.

@hgraceb
Copy link
Copy Markdown
Member Author

hgraceb commented Jul 17, 2024

@hgraceb You'll also have to get a test exemption for this change per the bot message above.

I have handled it now.

@stuartmorgan-g
Copy link
Copy Markdown
Contributor

test-exempt: removing code

Copy link
Copy Markdown
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for the contribution!

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 17, 2024
@auto-submit auto-submit bot merged commit 46cb56d into flutter:master Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
Remove redundant assignment of geometry.
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
Remove redundant assignment of geometry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants