Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing control flow collections #146601

Merged
merged 8 commits into from
Apr 15, 2024

Conversation

nate-thegrate
Copy link
Member

@nate-thegrate nate-thegrate commented Apr 10, 2024

This pull request aims for improved readability, based on issue #146600.

// before
Set<Color> _distinctVisibleColors() {
  final Set<Color> distinctVisibleColors = <Color>{};
  if (top.style != BorderStyle.none) {
    distinctVisibleColors.add(top.color);
  }
  if (right.style != BorderStyle.none) {
    distinctVisibleColors.add(right.color);
  }
  if (bottom.style != BorderStyle.none) {
    distinctVisibleColors.add(bottom.color);
  }
  if (left.style != BorderStyle.none) {
    distinctVisibleColors.add(left.color);
  }
  return distinctVisibleColors;
}


// after
Set<Color> _distinctVisibleColors() {
  return <Color>{
    if (top.style != BorderStyle.none) top.color,
    if (right.style != BorderStyle.none) right.color,
    if (bottom.style != BorderStyle.none) bottom.color,
    if (left.style != BorderStyle.none) left.color,
  };
}

Most of the repo should be covered in this PR (aside from flutter_tools/, since there was a lot going on in there).

Pre-launch Checklist

@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: integration_test The flutter/packages/integration_test plugin labels Apr 10, 2024
@nate-thegrate nate-thegrate changed the title implementing Control Flow Collections Implementing control flow collections Apr 10, 2024
@nate-thegrate nate-thegrate marked this pull request as ready for review April 10, 2024 22:13
Copy link
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

Thank you!

Copy link
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.

Flutter_LGTM

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 12, 2024
Copy link
Contributor

auto-submit bot commented Apr 12, 2024

auto label is removed for flutter/flutter/146601, due to Pull request flutter/flutter/146601 is not in a mergeable state.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 12, 2024
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thanks for making the codebase more readable as always.

final List<String> allExpectedFiles = binariesWithEntitlements(flutterRoot) + binariesWithoutEntitlements(flutterRoot);
final Set<String> foundFiles = <String>{
for (final String binaryPath in binaryPaths)
if (allExpectedFiles.contains(binaryPath)) binaryPath
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to double check the styleguide but looks like this is right. It should be on one line like this (as long as it fits in the line length). https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#prefer-single-line-for-short-collection-if-and-collection-for

];
options.add(benchmarkPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

That was a weird one...

return convertedActions;
return <AndroidSemanticsAction>[
for (final int id in actions)
if (AndroidSemanticsAction.deserialize(id) case final AndroidSemanticsAction action)
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know about this case syntax.

return <String?>[
for (final List<String?> slice in _chain) ...slice,
..._slice.sublist(0, _pointer),
].cast<String>();

Choose a reason for hiding this comment

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

Avoid .cast.
The result checks the value on every read and write, rather than once in constructing the list.
This kind of inefficiency should be avoided in the foundation.

Instead, nest a for-in in the control flow collection to make it equivalent to the original code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had no idea that .cast worked that way, thank you!

return result;
return <String?>[
for (final List<String?> slice in _chain) ...slice,
..._slice.sublist(0, _pointer),

Choose a reason for hiding this comment

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

..._slice.sublist(...) is creating an extra temporary list.
Presumably the original code avoided result.addAll(_slice.sublist(0, _pointer)) for some reason.

I would make this more like the original, i.e.
for (int i = 0; i < _pointer; i++) _slice[i]!,

@nate-thegrate
Copy link
Member Author

Thank you all very much!

It looks like a merge conflict popped up and autosubmit was removed, so if a kind soul is able to re-add it, that would be much appreciated.

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 15, 2024
@auto-submit auto-submit bot merged commit 2e748e8 into flutter:master Apr 15, 2024
140 checks passed
@nate-thegrate nate-thegrate deleted the clean-up-lists branch April 15, 2024 16:07
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 15, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 15, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 15, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Apr 15, 2024
…6541)

Manual roll requested by tarrinneal@google.com

flutter/flutter@53cba24...2e748e8

2024-04-15 nate.w5687@gmail.com Implementing control flow collections (flutter/flutter#146601)
2024-04-15 engine-flutter-autoroll@skia.org Roll Packages from 78f684c to 6698b2d (3 revisions) (flutter/flutter#146761)
2024-04-15 32538273+ValentinVignal@users.noreply.github.com test: Fix memory leak in transitions test (flutter/flutter#146747)
2024-04-15 leroux_bruno@yahoo.fr Fix filled text field active indicator overflows container bounds (flutter/flutter#146637)
2024-04-14 102401667+Dimilkalathiya@users.noreply.github.com - Fixes _DropdownMenuState leaking text controller (flutter/flutter#146571)
2024-04-13 32538273+ValentinVignal@users.noreply.github.com Fix memory leaks in `FloatingActionButton` (flutter/flutter#146711)
2024-04-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0e56e3dffe43 to 1a13c7d1f40e (2 revisions) (flutter/flutter#146703)
2024-04-12 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#146704)
2024-04-12 49699333+dependabot[bot]@users.noreply.github.com Bump peter-evans/create-pull-request from 6.0.2 to 6.0.3 (flutter/flutter#146702)
2024-04-12 chingjun@google.com Avoid forwarding the data after socket is disconnected. (flutter/flutter#146665)
2024-04-12 christopherfujino@gmail.com [flutter_tools] Fix conductor for package args roll (flutter/flutter#146646)
2024-04-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6b37b170998e to 0e56e3dffe43 (4 revisions) (flutter/flutter#146698)
2024-04-12 katelovett@google.com Light sliver clean up before SliverTree (flutter/flutter#146696)
2024-04-12 leroux_bruno@yahoo.fr Fix label text color is wrong for a focused and hovered TextField (flutter/flutter#146572)
2024-04-12 31859944+LongCatIsLooong@users.noreply.github.com Fix `getOffsetForCaret` crash (flutter/flutter#146669)
2024-04-12 magder@google.com Update gen_keycodes templates (flutter/flutter#146481)
2024-04-12 jacksongardner@google.com Support `flutter run --wasm` and `flutter drive --wasm`. (flutter/flutter#146231)
2024-04-12 32538273+ValentinVignal@users.noreply.github.com Fix curved animation memory leak for scrollbar (flutter/flutter#146670)
2024-04-12 engine-flutter-autoroll@skia.org Roll Packages from e98839a to 78f684c (6 revisions) (flutter/flutter#146691)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC rmistry@google.com,stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
This pull request aims for improved readability, based on issue flutter#146600.

```dart
// before
Set<Color> _distinctVisibleColors() {
  final Set<Color> distinctVisibleColors = <Color>{};
  if (top.style != BorderStyle.none) {
    distinctVisibleColors.add(top.color);
  }
  if (right.style != BorderStyle.none) {
    distinctVisibleColors.add(right.color);
  }
  if (bottom.style != BorderStyle.none) {
    distinctVisibleColors.add(bottom.color);
  }
  if (left.style != BorderStyle.none) {
    distinctVisibleColors.add(left.color);
  }
  return distinctVisibleColors;
}

// after
Set<Color> _distinctVisibleColors() {
  return <Color>{
    if (top.style != BorderStyle.none) top.color,
    if (right.style != BorderStyle.none) right.color,
    if (bottom.style != BorderStyle.none) bottom.color,
    if (left.style != BorderStyle.none) left.color,
  };
}
```

Most of the repo should be covered in this PR (aside from `flutter_tools/`, since there was a lot going on in there).
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
…lutter#6541)

Manual roll requested by tarrinneal@google.com

flutter/flutter@53cba24...2e748e8

2024-04-15 nate.w5687@gmail.com Implementing control flow collections (flutter/flutter#146601)
2024-04-15 engine-flutter-autoroll@skia.org Roll Packages from 78f684c to 6698b2d (3 revisions) (flutter/flutter#146761)
2024-04-15 32538273+ValentinVignal@users.noreply.github.com test: Fix memory leak in transitions test (flutter/flutter#146747)
2024-04-15 leroux_bruno@yahoo.fr Fix filled text field active indicator overflows container bounds (flutter/flutter#146637)
2024-04-14 102401667+Dimilkalathiya@users.noreply.github.com - Fixes _DropdownMenuState leaking text controller (flutter/flutter#146571)
2024-04-13 32538273+ValentinVignal@users.noreply.github.com Fix memory leaks in `FloatingActionButton` (flutter/flutter#146711)
2024-04-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0e56e3dffe43 to 1a13c7d1f40e (2 revisions) (flutter/flutter#146703)
2024-04-12 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#146704)
2024-04-12 49699333+dependabot[bot]@users.noreply.github.com Bump peter-evans/create-pull-request from 6.0.2 to 6.0.3 (flutter/flutter#146702)
2024-04-12 chingjun@google.com Avoid forwarding the data after socket is disconnected. (flutter/flutter#146665)
2024-04-12 christopherfujino@gmail.com [flutter_tools] Fix conductor for package args roll (flutter/flutter#146646)
2024-04-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6b37b170998e to 0e56e3dffe43 (4 revisions) (flutter/flutter#146698)
2024-04-12 katelovett@google.com Light sliver clean up before SliverTree (flutter/flutter#146696)
2024-04-12 leroux_bruno@yahoo.fr Fix label text color is wrong for a focused and hovered TextField (flutter/flutter#146572)
2024-04-12 31859944+LongCatIsLooong@users.noreply.github.com Fix `getOffsetForCaret` crash (flutter/flutter#146669)
2024-04-12 magder@google.com Update gen_keycodes templates (flutter/flutter#146481)
2024-04-12 jacksongardner@google.com Support `flutter run --wasm` and `flutter drive --wasm`. (flutter/flutter#146231)
2024-04-12 32538273+ValentinVignal@users.noreply.github.com Fix curved animation memory leak for scrollbar (flutter/flutter#146670)
2024-04-12 engine-flutter-autoroll@skia.org Roll Packages from e98839a to 78f684c (6 revisions) (flutter/flutter#146691)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC rmistry@google.com,stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…lutter#6541)

Manual roll requested by tarrinneal@google.com

flutter/flutter@53cba24...2e748e8

2024-04-15 nate.w5687@gmail.com Implementing control flow collections (flutter/flutter#146601)
2024-04-15 engine-flutter-autoroll@skia.org Roll Packages from 78f684c to 6698b2d (3 revisions) (flutter/flutter#146761)
2024-04-15 32538273+ValentinVignal@users.noreply.github.com test: Fix memory leak in transitions test (flutter/flutter#146747)
2024-04-15 leroux_bruno@yahoo.fr Fix filled text field active indicator overflows container bounds (flutter/flutter#146637)
2024-04-14 102401667+Dimilkalathiya@users.noreply.github.com - Fixes _DropdownMenuState leaking text controller (flutter/flutter#146571)
2024-04-13 32538273+ValentinVignal@users.noreply.github.com Fix memory leaks in `FloatingActionButton` (flutter/flutter#146711)
2024-04-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0e56e3dffe43 to 1a13c7d1f40e (2 revisions) (flutter/flutter#146703)
2024-04-12 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#146704)
2024-04-12 49699333+dependabot[bot]@users.noreply.github.com Bump peter-evans/create-pull-request from 6.0.2 to 6.0.3 (flutter/flutter#146702)
2024-04-12 chingjun@google.com Avoid forwarding the data after socket is disconnected. (flutter/flutter#146665)
2024-04-12 christopherfujino@gmail.com [flutter_tools] Fix conductor for package args roll (flutter/flutter#146646)
2024-04-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6b37b170998e to 0e56e3dffe43 (4 revisions) (flutter/flutter#146698)
2024-04-12 katelovett@google.com Light sliver clean up before SliverTree (flutter/flutter#146696)
2024-04-12 leroux_bruno@yahoo.fr Fix label text color is wrong for a focused and hovered TextField (flutter/flutter#146572)
2024-04-12 31859944+LongCatIsLooong@users.noreply.github.com Fix `getOffsetForCaret` crash (flutter/flutter#146669)
2024-04-12 magder@google.com Update gen_keycodes templates (flutter/flutter#146481)
2024-04-12 jacksongardner@google.com Support `flutter run --wasm` and `flutter drive --wasm`. (flutter/flutter#146231)
2024-04-12 32538273+ValentinVignal@users.noreply.github.com Fix curved animation memory leak for scrollbar (flutter/flutter#146670)
2024-04-12 engine-flutter-autoroll@skia.org Roll Packages from e98839a to 78f684c (6 revisions) (flutter/flutter#146691)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC rmistry@google.com,stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@nate-thegrate nate-thegrate added the refactor Improving readability/efficiency without behavioral changes label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: integration_test The flutter/packages/integration_test plugin f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. refactor Improving readability/efficiency without behavioral changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants