Skip to content

Commit

Permalink
[dart2wasm] Use the same Dart object when to{Upper,Lower}Case returns…
Browse files Browse the repository at this point in the history
… the argument

This fixes `identical` checks when the input doesn't need case mapping.

This change was originally made in [1], but I'm trying to split it into
smaller CLs as it currently has a lot of conflicts with the main branch.

[1]: https://dart-review.googlesource.com/c/sdk/+/316628

Change-Id: I88da52a3a73c9d587acefe2b14fd39edaf01c966
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332200
Reviewed-by: Aske Simon Christensen <[email protected]>
Commit-Queue: Ömer Ağacan <[email protected]>
  • Loading branch information
osa1 authored and Commit Queue committed Nov 2, 2023
1 parent 12c4e22 commit d0a2656
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions sdk/lib/_internal/wasm/lib/js_string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,20 @@ final class JSStringImpl implements String {

@override
String toLowerCase() {
return JSStringImpl(
js.JS<WasmExternRef?>('s => s.toLowerCase()', toExternRef));
final thisRef = toExternRef;
final lowerCaseRef = js.JS<WasmExternRef?>('s => s.toLowerCase()', thisRef);
return _jsIdentical(thisRef, lowerCaseRef)
? this
: JSStringImpl(lowerCaseRef);
}

@override
String toUpperCase() {
return JSStringImpl(
js.JS<WasmExternRef?>('s => s.toUpperCase()', toExternRef));
final thisRef = toExternRef;
final upperCaseRef = js.JS<WasmExternRef?>('s => s.toUpperCase()', thisRef);
return _jsIdentical(thisRef, upperCaseRef)
? this
: JSStringImpl(upperCaseRef);
}

// Characters with Whitespace property (Unicode 6.3).
Expand Down Expand Up @@ -679,3 +685,6 @@ JSStringImpl _jsStringToJSStringImpl(WasmExternRef? string) =>
@pragma("wasm:export", "\$jsStringFromJSStringImpl")
WasmExternRef? _jsStringFromJSStringImpl(JSStringImpl string) =>
string.toExternRef;

bool _jsIdentical(WasmExternRef? ref1, WasmExternRef? ref2) =>
js.JS<bool>('Object.is', ref1, ref2);

0 comments on commit d0a2656

Please sign in to comment.