Skip to content

Commit 54217bd

Browse files
authored
Remove unnecessary null checks in dev/benchmarks (#118840)
* Remove unnecessary null checks in dev/benchmarks * empty
1 parent ec51d32 commit 54217bd

13 files changed

+18
-69
lines changed

dev/benchmarks/complex_layout/test_driver/scroll_perf_bad_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ void main() {
1818
});
1919

2020
tearDownAll(() async {
21-
if (driver != null) {
22-
driver.close();
23-
}
21+
driver.close();
2422
});
2523

2624
Future<void> testScrollPerf(String listKey, String summaryName) async {

dev/benchmarks/complex_layout/test_driver/scroll_perf_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ void main() {
1818
});
1919

2020
tearDownAll(() async {
21-
if (driver != null) {
22-
driver.close();
23-
}
21+
driver.close();
2422
});
2523

2624
Future<void> testScrollPerf(String listKey, String summaryName) async {

dev/benchmarks/complex_layout/test_driver/semantics_perf_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ void main() {
3434
});
3535

3636
tearDownAll(() async {
37-
if (driver != null) {
38-
driver.close();
39-
}
37+
driver.close();
4038
});
4139

4240
test('initial tree creation', () async {

dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ class _Tester {
159159
final Stopwatch stopwatch = Stopwatch()..start();
160160
await gesture.moveTo(location, timeStamp: currentTime);
161161
stopwatch.stop();
162-
if (onDataPoint != null) {
163-
onDataPoint(stopwatch.elapsed);
164-
}
162+
onDataPoint(stopwatch.elapsed);
165163
await _UntilNextFrame.wait();
166164
}
167165

dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_mixed_grid_hover.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ class _Tester {
181181
final Stopwatch stopwatch = Stopwatch()..start();
182182
await gesture.moveTo(location, timeStamp: currentTime);
183183
stopwatch.stop();
184-
if (onDataPoint != null) {
185-
onDataPoint(stopwatch.elapsed);
186-
}
184+
onDataPoint(stopwatch.elapsed);
187185
await _UntilNextFrame.wait();
188186
}
189187

dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_layout.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ class ColorItem extends StatelessWidget {
340340
required this.index,
341341
required this.color,
342342
this.prefix = '',
343-
}) : assert(index != null),
344-
assert(color != null),
345-
assert(prefix != null);
343+
});
346344

347345
final int index;
348346
final Color color;

dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,7 @@ class Profile {
841841
/// If [useCustomWarmUp] is true the benchmark will continue running until
842842
/// [stopBenchmark] is called. Otherwise, the benchmark collects the
843843
/// [kDefaultTotalSampleCount] samples and stops automatically.
844-
Profile({required this.name, this.useCustomWarmUp = false})
845-
: assert(name != null);
844+
Profile({required this.name, this.useCustomWarmUp = false});
846845

847846
/// The name of the benchmark that produced this profile.
848847
final String name;
@@ -1296,13 +1295,6 @@ final Map<String, EngineBenchmarkValueListener> _engineBenchmarkListeners = <Str
12961295
///
12971296
/// If another listener is already registered, overrides it.
12981297
void registerEngineBenchmarkValueListener(String name, EngineBenchmarkValueListener listener) {
1299-
if (listener == null) {
1300-
throw ArgumentError(
1301-
'Listener must not be null. To stop listening to engine benchmark values '
1302-
'under label "$name", call stopListeningToEngineBenchmarkValues(\'$name\').',
1303-
);
1304-
}
1305-
13061298
if (_engineBenchmarkListeners.containsKey(name)) {
13071299
throw StateError(
13081300
'A listener for "$name" is already registered.\n'

dev/benchmarks/microbenchmarks/lib/language/sync_star_semantics_bench.dart

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
8383
String? workingLabel;
8484
for (final InlineSpanSemanticsInformation info in inputs) {
8585
if (info.requiresOwnNode) {
86-
if (workingText != null) {
87-
yield InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText);
88-
workingText = '';
89-
workingLabel = null;
90-
}
86+
yield InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText);
87+
workingText = '';
88+
workingLabel = null;
9189
yield info;
9290
} else {
9391
workingText += info.text;
@@ -100,11 +98,7 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
10098
}
10199
}
102100
}
103-
if (workingText != null) {
104-
yield InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel);
105-
} else {
106-
assert(workingLabel != null);
107-
}
101+
assert(workingLabel != null);
108102
}
109103

110104
Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpanSemanticsInformation> inputs) {
@@ -113,11 +107,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa
113107
final List<InlineSpanSemanticsInformation> result = <InlineSpanSemanticsInformation>[];
114108
for (final InlineSpanSemanticsInformation info in inputs) {
115109
if (info.requiresOwnNode) {
116-
if (workingText != null) {
117-
result.add(InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText));
118-
workingText = '';
119-
workingLabel = null;
120-
}
110+
result.add(InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText));
111+
workingText = '';
112+
workingLabel = null;
121113
result.add(info);
122114
} else {
123115
workingText += info.text;
@@ -130,10 +122,6 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa
130122
}
131123
}
132124
}
133-
if (workingText != null) {
134-
result.add(InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel));
135-
} else {
136-
assert(workingLabel != null);
137-
}
125+
assert(workingLabel != null);
138126
return result;
139127
}

dev/benchmarks/test_apps/stocks/lib/stock_data.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ class StockData extends ChangeNotifier {
7878
void _fetchNextChunk() {
7979
_httpClient!.get(_urlToFetch(_nextChunk++)).then<void>((http.Response response) {
8080
final String json = response.body;
81-
if (json == null) {
82-
debugPrint('Failed to load stock data chunk ${_nextChunk - 1}');
83-
_end();
84-
return;
85-
}
8681
const JsonDecoder decoder = JsonDecoder();
8782
add(decoder.convert(json) as List<dynamic>);
8883
if (_nextChunk < _chunkCount) {

dev/benchmarks/test_apps/stocks/lib/stock_home.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ class StockHomeState extends State<StockHome> {
8585
}
8686

8787
void _handleStockModeChange(StockMode? value) {
88-
if (widget.updater != null) {
89-
widget.updater(widget.configuration.copyWith(stockMode: value));
90-
}
88+
widget.updater(widget.configuration.copyWith(stockMode: value));
9189
}
9290

9391
void _handleStockMenu(BuildContext context, _StockMenuItem value) {

dev/benchmarks/test_apps/stocks/lib/stock_settings.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ class StockSettingsState extends State<StockSettings> {
9393
}
9494

9595
void sendUpdates(StockConfiguration value) {
96-
if (widget.updater != null) {
97-
widget.updater(value);
98-
}
96+
widget.updater(value);
9997
}
10098

10199
AppBar buildAppBar(BuildContext context) {

dev/benchmarks/test_apps/stocks/lib/stock_symbol_viewer.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class _StockSymbolView extends StatelessWidget {
1818

1919
@override
2020
Widget build(BuildContext context) {
21-
assert(stock != null);
2221
final String lastSale = '\$${stock.lastSale.toStringAsFixed(2)}';
2322
String changeInPrice = '${stock.percentChange.toStringAsFixed(2)}%';
2423
if (stock.percentChange > 0) {

dev/benchmarks/test_apps/stocks/lib/stock_types.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,7 @@ class StockConfiguration {
1717
required this.debugShowRainbow,
1818
required this.showPerformanceOverlay,
1919
required this.showSemanticsDebugger,
20-
}) : assert(stockMode != null),
21-
assert(backupMode != null),
22-
assert(debugShowGrid != null),
23-
assert(debugShowSizes != null),
24-
assert(debugShowBaselines != null),
25-
assert(debugShowLayers != null),
26-
assert(debugShowPointers != null),
27-
assert(debugShowRainbow != null),
28-
assert(showPerformanceOverlay != null),
29-
assert(showSemanticsDebugger != null);
20+
});
3021

3122
final StockMode stockMode;
3223
final BackupMode backupMode;

0 commit comments

Comments
 (0)