Skip to content

Commit cf5218c

Browse files
rajveermalviyagnprice
authored andcommitted
api: Switch to fused JSON + UTF-8 decoder for parsing response
1 parent 316cc1a commit cf5218c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/api/core.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import '../log.dart';
77
import '../model/localizations.dart';
88
import 'exception.dart';
99

10+
/// A fused JSON + UTF-8 decoder.
11+
///
12+
/// This object is an instance of [`_JsonUtf8Decoder`][1] which is
13+
/// a fast-path present in VM and WASM standard library implementations.
14+
///
15+
/// [1]: https://github.com/dart-lang/sdk/blob/6c7452ac1530fe6161023c9b3007764ab26cc96d/sdk/lib/_internal/vm/lib/convert_patch.dart#L55
16+
final jsonUtf8Decoder = const Utf8Decoder().fuse(const JsonDecoder());
17+
1018
/// A value for an API request parameter, to use directly without JSON encoding.
1119
class RawParameter {
1220
RawParameter(this.value);
@@ -105,7 +113,7 @@ class ApiConnection {
105113
Map<String, dynamic>? json;
106114
try {
107115
final bytes = await response.stream.toBytes();
108-
json = jsonDecode(utf8.decode(bytes));
116+
json = jsonUtf8Decoder.convert(bytes) as Map<String, dynamic>?;
109117
} catch (e) {
110118
// We'll throw something below, seeing `json` is null.
111119
}

0 commit comments

Comments
 (0)