Skip to content

Commit 4d4a922

Browse files
mkustermannCommit Queue
authored andcommitted
[benchmarks] Remove unnecessary utf8.encode() as Uint8List downcast
The return type of `utf8.encode()` was made more precise in [0] (from `List<int>` 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 <[email protected]> Reviewed-by: Daco Harkes <[email protected]>
1 parent 70310b0 commit 4d4a922

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

benchmarks/IsolateJson/dart/IsolateJson.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Uint8List createSampleJson(final size) {
4242
for (int i = 0; i < size; i++) {
4343
map['$i'] = list;
4444
}
45-
return utf8.encode(json.encode(map)) as Uint8List;
45+
return utf8.encode(json.encode(map));
4646
}
4747

4848
class JsonDecodeRequest {
@@ -113,22 +113,19 @@ class BenchmarkConfig {
113113
Future<void> main() async {
114114
final jsonString =
115115
File('benchmarks/IsolateJson/dart/sample.json').readAsStringSync();
116-
final json250KB = utf8.encode(jsonString) as Uint8List; // 294356 bytes
116+
final json250KB = utf8.encode(jsonString); // 294356 bytes
117117
final decoded = json.decode(utf8.decode(json250KB));
118118
final decoded1MB = <dynamic, dynamic>{
119119
'1': decoded['1'],
120120
'2': decoded['1'],
121121
'3': decoded['1'],
122122
'4': decoded['1'],
123123
};
124-
final json1MB =
125-
utf8.encode(json.encode(decoded1MB)) as Uint8List; // 1177397 bytes
124+
final json1MB = utf8.encode(json.encode(decoded1MB)); // 1177397 bytes
126125
decoded['1'] = (decoded['1'] as List).sublist(0, 200);
127-
final json100KB =
128-
utf8.encode(json.encode(decoded)) as Uint8List; // 104685 bytes
126+
final json100KB = utf8.encode(json.encode(decoded)); // 104685 bytes
129127
decoded['1'] = (decoded['1'] as List).sublist(0, 100);
130-
final json50KB =
131-
utf8.encode(json.encode(decoded)) as Uint8List; // 51760 bytes
128+
final json50KB = utf8.encode(json.encode(decoded)); // 51760 bytes
132129

133130
final configs = <BenchmarkConfig>[
134131
BenchmarkConfig('50KB', json50KB),

benchmarks/Utf8Decode/dart/Utf8Decode.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Utf8Decode extends BenchmarkBase {
3939

4040
@override
4141
void setup() {
42-
final Uint8List data = utf8.encode(text) as Uint8List;
42+
final Uint8List data = utf8.encode(text);
4343
if (data.length != 10000) {
4444
throw 'Expected input data of exactly 10000 bytes.';
4545
}

benchmarks/Utf8Decode/dart2/Utf8Decode.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Utf8Decode extends BenchmarkBase {
4141

4242
@override
4343
void setup() {
44-
final Uint8List data = utf8.encode(text) as Uint8List;
44+
final Uint8List data = utf8.encode(text);
4545
if (data.length != 10000) {
4646
throw 'Expected input data of exactly 10000 bytes.';
4747
}

0 commit comments

Comments
 (0)