Implementing control flow collections (#146601)

This pull request aims for improved readability, based on issue #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).
This commit is contained in:
Nate
2024-04-15 11:06:07 -05:00
committed by GitHub
parent 600787891a
commit 2e748e8598
37 changed files with 276 additions and 494 deletions

View File

@@ -11,30 +11,20 @@ import 'package:flutter/services.dart';
import 'package:microbenchmarks/common.dart';
List<Object?> _makeTestBuffer(int size) {
final List<Object?> answer = <Object?>[];
for (int i = 0; i < size; ++i) {
switch (i % 9) {
case 0:
answer.add(1);
case 1:
answer.add(math.pow(2, 65));
case 2:
answer.add(1234.0);
case 3:
answer.add(null);
case 4:
answer.add(<int>[1234]);
case 5:
answer.add(<String, int>{'hello': 1234});
case 6:
answer.add('this is a test');
case 7:
answer.add(true);
case 8:
answer.add(Uint8List(64));
}
}
return answer;
return <Object?>[
for (int i = 0; i < size; i++)
switch (i % 9) {
0 => 1,
1 => math.pow(2, 65),
2 => 1234.0,
3 => null,
4 => <int>[1234],
5 => <String, int>{'hello': 1234},
6 => 'this is a test',
7 => true,
_ => Uint8List(64),
},
];
}
Future<double> _runBasicStandardSmall(