mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 18:31:32 +00:00
[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:
parent
a3d5e1d59d
commit
fc4b352f2d
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue