[dart2wasm] Use unsigned comparison in list bounds checks

In typed data classes we've found that this optimization in bounds
checks can be quite significant. This does the same optimizations in
List classes.

Change-Id: Ia6e80d5aafa621398ed7b7175be8794838e82b89
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337725
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Ömer Sinan Ağacan 2023-12-04 09:58:17 +00:00 committed by Commit Queue
parent a3d5e1d59d
commit fc4b352f2d

View file

@ -23,7 +23,9 @@ abstract class _ListBase<E> extends ListBase<E> {
_ListBase._withData(this._length, this._data);
E operator [](int index) {
IndexError.check(index, _length, indexable: this, name: "[]");
if (WasmI64.fromInt(_length).leU(WasmI64.fromInt(index))) {
throw IndexError.withLength(index, length, name: "[]");
}
return unsafeCast(_data.read(index));
}
@ -58,7 +60,9 @@ abstract class _ModifiableList<E> extends _ListBase<E> {
: super._withData(length, data);
void operator []=(int index, E value) {
IndexError.check(index, _length, indexable: this, name: "[]=");
if (WasmI64.fromInt(_length).leU(WasmI64.fromInt(index))) {
throw IndexError.withLength(index, length, name: "[]=");
}
_data.write(index, value);
}