Skip to content

Commit 9233056

Browse files
osa1Commit Queue
authored andcommitted
[dart2wasm] Move _Utf8Decoder.convertGeneral to JSCM patch
This method is only used in JSCM `dart:convert` patch. Move it from the standard library to JSCM patch file. This makes it easier to optimize it using dar2wasm internal types. Change-Id: I17139f0a752b856d17ddfb8b5ff047f17d5aaa70 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403986 Reviewed-by: Lasse Nielsen <[email protected]> Reviewed-by: Stephen Adams <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent cc5612e commit 9233056

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

sdk/lib/_internal/wasm_js_compatibility/lib/convert_patch.dart

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,12 +1503,44 @@ class _Utf8Decoder {
15031503
if (decoded != null) return decoded;
15041504
}
15051505

1506-
return convertGeneral(codeUnits, start, maybeEnd, true);
1506+
return _convertGeneral(codeUnits, start, maybeEnd, true);
15071507
}
15081508

15091509
@patch
15101510
String convertChunked(List<int> codeUnits, int start, int? maybeEnd) {
1511-
return convertGeneral(codeUnits, start, maybeEnd, false);
1511+
return _convertGeneral(codeUnits, start, maybeEnd, false);
1512+
}
1513+
1514+
String _convertGeneral(
1515+
List<int> codeUnits,
1516+
int start,
1517+
int? maybeEnd,
1518+
bool single,
1519+
) {
1520+
int end = RangeError.checkValidRange(start, maybeEnd, codeUnits.length);
1521+
1522+
if (start == end) return "";
1523+
1524+
// Have bytes as Uint8List.
1525+
Uint8List bytes;
1526+
int errorOffset;
1527+
if (codeUnits is Uint8List) {
1528+
bytes = codeUnits;
1529+
errorOffset = 0;
1530+
} else {
1531+
bytes = _makeUint8List(codeUnits, start, end);
1532+
errorOffset = start;
1533+
end -= start;
1534+
start = 0;
1535+
}
1536+
1537+
String result = decodeGeneral(bytes, start, end, single);
1538+
if (isErrorState(_state)) {
1539+
String message = errorDescription(_state);
1540+
_state = initial; // Ready for more input.
1541+
throw FormatException(message, codeUnits, errorOffset + _charOrIndex);
1542+
}
1543+
return result;
15121544
}
15131545
}
15141546

sdk/lib/convert/utf.dart

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -552,38 +552,6 @@ class _Utf8Decoder {
552552

553553
external String convertChunked(List<int> codeUnits, int start, int? maybeEnd);
554554

555-
String convertGeneral(
556-
List<int> codeUnits,
557-
int start,
558-
int? maybeEnd,
559-
bool single,
560-
) {
561-
int end = RangeError.checkValidRange(start, maybeEnd, codeUnits.length);
562-
563-
if (start == end) return "";
564-
565-
// Have bytes as Uint8List.
566-
Uint8List bytes;
567-
int errorOffset;
568-
if (codeUnits is Uint8List) {
569-
bytes = codeUnits;
570-
errorOffset = 0;
571-
} else {
572-
bytes = _makeUint8List(codeUnits, start, end);
573-
errorOffset = start;
574-
end -= start;
575-
start = 0;
576-
}
577-
578-
String result = decodeGeneral(bytes, start, end, single);
579-
if (isErrorState(_state)) {
580-
String message = errorDescription(_state);
581-
_state = initial; // Ready for more input.
582-
throw FormatException(message, codeUnits, errorOffset + _charOrIndex);
583-
}
584-
return result;
585-
}
586-
587555
/// Flushes this decoder as if closed.
588556
///
589557
/// This method throws if the input was partial and the decoder was

0 commit comments

Comments
 (0)