Skip to content

Commit

Permalink
[dart2wasm] Move _Utf8Decoder.convertGeneral to JSCM patch
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
osa1 authored and Commit Queue committed Jan 22, 2025
1 parent cc5612e commit 9233056
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
36 changes: 34 additions & 2 deletions sdk/lib/_internal/wasm_js_compatibility/lib/convert_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1503,12 +1503,44 @@ class _Utf8Decoder {
if (decoded != null) return decoded;
}

return convertGeneral(codeUnits, start, maybeEnd, true);
return _convertGeneral(codeUnits, start, maybeEnd, true);
}

@patch
String convertChunked(List<int> codeUnits, int start, int? maybeEnd) {
return convertGeneral(codeUnits, start, maybeEnd, false);
return _convertGeneral(codeUnits, start, maybeEnd, false);
}

String _convertGeneral(
List<int> codeUnits,
int start,
int? maybeEnd,
bool single,
) {
int end = RangeError.checkValidRange(start, maybeEnd, codeUnits.length);

if (start == end) return "";

// Have bytes as Uint8List.
Uint8List bytes;
int errorOffset;
if (codeUnits is Uint8List) {
bytes = codeUnits;
errorOffset = 0;
} else {
bytes = _makeUint8List(codeUnits, start, end);
errorOffset = start;
end -= start;
start = 0;
}

String result = decodeGeneral(bytes, start, end, single);
if (isErrorState(_state)) {
String message = errorDescription(_state);
_state = initial; // Ready for more input.
throw FormatException(message, codeUnits, errorOffset + _charOrIndex);
}
return result;
}
}

Expand Down
32 changes: 0 additions & 32 deletions sdk/lib/convert/utf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -552,38 +552,6 @@ class _Utf8Decoder {

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

String convertGeneral(
List<int> codeUnits,
int start,
int? maybeEnd,
bool single,
) {
int end = RangeError.checkValidRange(start, maybeEnd, codeUnits.length);

if (start == end) return "";

// Have bytes as Uint8List.
Uint8List bytes;
int errorOffset;
if (codeUnits is Uint8List) {
bytes = codeUnits;
errorOffset = 0;
} else {
bytes = _makeUint8List(codeUnits, start, end);
errorOffset = start;
end -= start;
start = 0;
}

String result = decodeGeneral(bytes, start, end, single);
if (isErrorState(_state)) {
String message = errorDescription(_state);
_state = initial; // Ready for more input.
throw FormatException(message, codeUnits, errorOffset + _charOrIndex);
}
return result;
}

/// Flushes this decoder as if closed.
///
/// This method throws if the input was partial and the decoder was
Expand Down

0 comments on commit 9233056

Please sign in to comment.