Skip to content

Commit

Permalink
Remove unnecessary null checks in dev/benchmarks (#118840)
Browse files Browse the repository at this point in the history
* Remove unnecessary null checks in dev/benchmarks

* empty
  • Loading branch information
goderbauer committed Jan 20, 2023
1 parent ec51d32 commit 54217bd
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ void main() {
});

tearDownAll(() async {
if (driver != null) {
driver.close();
}
driver.close();
});

Future<void> testScrollPerf(String listKey, String summaryName) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ void main() {
});

tearDownAll(() async {
if (driver != null) {
driver.close();
}
driver.close();
});

Future<void> testScrollPerf(String listKey, String summaryName) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ void main() {
});

tearDownAll(() async {
if (driver != null) {
driver.close();
}
driver.close();
});

test('initial tree creation', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ class _Tester {
final Stopwatch stopwatch = Stopwatch()..start();
await gesture.moveTo(location, timeStamp: currentTime);
stopwatch.stop();
if (onDataPoint != null) {
onDataPoint(stopwatch.elapsed);
}
onDataPoint(stopwatch.elapsed);
await _UntilNextFrame.wait();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ class _Tester {
final Stopwatch stopwatch = Stopwatch()..start();
await gesture.moveTo(location, timeStamp: currentTime);
stopwatch.stop();
if (onDataPoint != null) {
onDataPoint(stopwatch.elapsed);
}
onDataPoint(stopwatch.elapsed);
await _UntilNextFrame.wait();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ class ColorItem extends StatelessWidget {
required this.index,
required this.color,
this.prefix = '',
}) : assert(index != null),
assert(color != null),
assert(prefix != null);
});

final int index;
final Color color;
Expand Down
10 changes: 1 addition & 9 deletions dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,7 @@ class Profile {
/// If [useCustomWarmUp] is true the benchmark will continue running until
/// [stopBenchmark] is called. Otherwise, the benchmark collects the
/// [kDefaultTotalSampleCount] samples and stops automatically.
Profile({required this.name, this.useCustomWarmUp = false})
: assert(name != null);
Profile({required this.name, this.useCustomWarmUp = false});

/// The name of the benchmark that produced this profile.
final String name;
Expand Down Expand Up @@ -1296,13 +1295,6 @@ final Map<String, EngineBenchmarkValueListener> _engineBenchmarkListeners = <Str
///
/// If another listener is already registered, overrides it.
void registerEngineBenchmarkValueListener(String name, EngineBenchmarkValueListener listener) {
if (listener == null) {
throw ArgumentError(
'Listener must not be null. To stop listening to engine benchmark values '
'under label "$name", call stopListeningToEngineBenchmarkValues(\'$name\').',
);
}

if (_engineBenchmarkListeners.containsKey(name)) {
throw StateError(
'A listener for "$name" is already registered.\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
String? workingLabel;
for (final InlineSpanSemanticsInformation info in inputs) {
if (info.requiresOwnNode) {
if (workingText != null) {
yield InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText);
workingText = '';
workingLabel = null;
}
yield InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText);
workingText = '';
workingLabel = null;
yield info;
} else {
workingText += info.text;
Expand All @@ -100,11 +98,7 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
}
}
}
if (workingText != null) {
yield InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel);
} else {
assert(workingLabel != null);
}
assert(workingLabel != null);
}

Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpanSemanticsInformation> inputs) {
Expand All @@ -113,11 +107,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa
final List<InlineSpanSemanticsInformation> result = <InlineSpanSemanticsInformation>[];
for (final InlineSpanSemanticsInformation info in inputs) {
if (info.requiresOwnNode) {
if (workingText != null) {
result.add(InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText));
workingText = '';
workingLabel = null;
}
result.add(InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText));
workingText = '';
workingLabel = null;
result.add(info);
} else {
workingText += info.text;
Expand All @@ -130,10 +122,6 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa
}
}
}
if (workingText != null) {
result.add(InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel));
} else {
assert(workingLabel != null);
}
assert(workingLabel != null);
return result;
}
5 changes: 0 additions & 5 deletions dev/benchmarks/test_apps/stocks/lib/stock_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ class StockData extends ChangeNotifier {
void _fetchNextChunk() {
_httpClient!.get(_urlToFetch(_nextChunk++)).then<void>((http.Response response) {
final String json = response.body;
if (json == null) {
debugPrint('Failed to load stock data chunk ${_nextChunk - 1}');
_end();
return;
}
const JsonDecoder decoder = JsonDecoder();
add(decoder.convert(json) as List<dynamic>);
if (_nextChunk < _chunkCount) {
Expand Down
4 changes: 1 addition & 3 deletions dev/benchmarks/test_apps/stocks/lib/stock_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ class StockHomeState extends State<StockHome> {
}

void _handleStockModeChange(StockMode? value) {
if (widget.updater != null) {
widget.updater(widget.configuration.copyWith(stockMode: value));
}
widget.updater(widget.configuration.copyWith(stockMode: value));
}

void _handleStockMenu(BuildContext context, _StockMenuItem value) {
Expand Down
4 changes: 1 addition & 3 deletions dev/benchmarks/test_apps/stocks/lib/stock_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ class StockSettingsState extends State<StockSettings> {
}

void sendUpdates(StockConfiguration value) {
if (widget.updater != null) {
widget.updater(value);
}
widget.updater(value);
}

AppBar buildAppBar(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class _StockSymbolView extends StatelessWidget {

@override
Widget build(BuildContext context) {
assert(stock != null);
final String lastSale = '\$${stock.lastSale.toStringAsFixed(2)}';
String changeInPrice = '${stock.percentChange.toStringAsFixed(2)}%';
if (stock.percentChange > 0) {
Expand Down
11 changes: 1 addition & 10 deletions dev/benchmarks/test_apps/stocks/lib/stock_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ class StockConfiguration {
required this.debugShowRainbow,
required this.showPerformanceOverlay,
required this.showSemanticsDebugger,
}) : assert(stockMode != null),
assert(backupMode != null),
assert(debugShowGrid != null),
assert(debugShowSizes != null),
assert(debugShowBaselines != null),
assert(debugShowLayers != null),
assert(debugShowPointers != null),
assert(debugShowRainbow != null),
assert(showPerformanceOverlay != null),
assert(showSemanticsDebugger != null);
});

final StockMode stockMode;
final BackupMode backupMode;
Expand Down

0 comments on commit 54217bd

Please sign in to comment.