From 4d4a922638cda394c59605936a56874f75819b9e Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Mon, 21 Aug 2023 08:21:37 +0000 Subject: [PATCH] [benchmarks] Remove unnecessary `utf8.encode() as Uint8List` downcast The return type of `utf8.encode()` was made more precise in [0] (from `List` to `Uint8List`) [0] https://dart-review.googlesource.com/c/sdk/+/254903 TEST=ci Change-Id: I3e578ac8dc5f3f66396cb374e3dcadd989919518 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321860 Commit-Queue: Martin Kustermann Reviewed-by: Daco Harkes --- benchmarks/IsolateJson/dart/IsolateJson.dart | 13 +++++-------- benchmarks/Utf8Decode/dart/Utf8Decode.dart | 2 +- benchmarks/Utf8Decode/dart2/Utf8Decode.dart | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/benchmarks/IsolateJson/dart/IsolateJson.dart b/benchmarks/IsolateJson/dart/IsolateJson.dart index 9717f34f7ce..bc13e057c50 100644 --- a/benchmarks/IsolateJson/dart/IsolateJson.dart +++ b/benchmarks/IsolateJson/dart/IsolateJson.dart @@ -42,7 +42,7 @@ Uint8List createSampleJson(final size) { for (int i = 0; i < size; i++) { map['$i'] = list; } - return utf8.encode(json.encode(map)) as Uint8List; + return utf8.encode(json.encode(map)); } class JsonDecodeRequest { @@ -113,7 +113,7 @@ class BenchmarkConfig { Future main() async { final jsonString = File('benchmarks/IsolateJson/dart/sample.json').readAsStringSync(); - final json250KB = utf8.encode(jsonString) as Uint8List; // 294356 bytes + final json250KB = utf8.encode(jsonString); // 294356 bytes final decoded = json.decode(utf8.decode(json250KB)); final decoded1MB = { '1': decoded['1'], @@ -121,14 +121,11 @@ Future main() async { '3': decoded['1'], '4': decoded['1'], }; - final json1MB = - utf8.encode(json.encode(decoded1MB)) as Uint8List; // 1177397 bytes + final json1MB = utf8.encode(json.encode(decoded1MB)); // 1177397 bytes decoded['1'] = (decoded['1'] as List).sublist(0, 200); - final json100KB = - utf8.encode(json.encode(decoded)) as Uint8List; // 104685 bytes + final json100KB = utf8.encode(json.encode(decoded)); // 104685 bytes decoded['1'] = (decoded['1'] as List).sublist(0, 100); - final json50KB = - utf8.encode(json.encode(decoded)) as Uint8List; // 51760 bytes + final json50KB = utf8.encode(json.encode(decoded)); // 51760 bytes final configs = [ BenchmarkConfig('50KB', json50KB), diff --git a/benchmarks/Utf8Decode/dart/Utf8Decode.dart b/benchmarks/Utf8Decode/dart/Utf8Decode.dart index 504debe2368..e37eadf00a1 100644 --- a/benchmarks/Utf8Decode/dart/Utf8Decode.dart +++ b/benchmarks/Utf8Decode/dart/Utf8Decode.dart @@ -39,7 +39,7 @@ class Utf8Decode extends BenchmarkBase { @override void setup() { - final Uint8List data = utf8.encode(text) as Uint8List; + final Uint8List data = utf8.encode(text); if (data.length != 10000) { throw 'Expected input data of exactly 10000 bytes.'; } diff --git a/benchmarks/Utf8Decode/dart2/Utf8Decode.dart b/benchmarks/Utf8Decode/dart2/Utf8Decode.dart index 03c87edad1f..98dd260f769 100644 --- a/benchmarks/Utf8Decode/dart2/Utf8Decode.dart +++ b/benchmarks/Utf8Decode/dart2/Utf8Decode.dart @@ -41,7 +41,7 @@ class Utf8Decode extends BenchmarkBase { @override void setup() { - final Uint8List data = utf8.encode(text) as Uint8List; + final Uint8List data = utf8.encode(text); if (data.length != 10000) { throw 'Expected input data of exactly 10000 bytes.'; }