Skip to content

Commit

Permalink
[dart2wasm] Add inline pragmas to JS typed array classes
Browse files Browse the repository at this point in the history
Typed array accessors are quite small, and inlining them often leads to
avoiding boxing the return values in `operator []` and the set value in
`operator []=`.

(Native typed array classes already have these inline pragmas)

Change-Id: Ib15dda93687b5becd1dfa92d34d9d28a75df2e07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329100
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
  • Loading branch information
osa1 authored and Commit Queue committed Oct 5, 2023
1 parent f8086ed commit c5dd320
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sdk/lib/_internal/wasm/lib/js_typed_array.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ final class JSIntArrayImpl extends JSArrayBufferViewImpl
JSIntArrayImpl(super._ref);

@override
@pragma("wasm:prefer-inline")
int operator [](int index) {
IndexError.check(index, length);
return js
Expand All @@ -238,6 +239,7 @@ final class JSIntArrayImpl extends JSArrayBufferViewImpl
}

@override
@pragma("wasm:prefer-inline")
void operator []=(int index, int value) {
IndexError.check(index, length);
js.JS<void>('(o, i, v) => o[i] = v', toExternRef, index.toDouble(),
Expand Down Expand Up @@ -501,6 +503,7 @@ final class JSInt32x4ArrayImpl
int get length => _storage.length ~/ 4;

@override
@pragma("wasm:prefer-inline")
Int32x4 operator [](int index) {
IndexError.check(index, length);
int _x = _storage[(index * 4) + 0];
Expand All @@ -511,6 +514,7 @@ final class JSInt32x4ArrayImpl
}

@override
@pragma("wasm:prefer-inline")
void operator []=(int index, Int32x4 value) {
IndexError.check(index, length);
_storage[(index * 4) + 0] = value.x;
Expand All @@ -531,12 +535,14 @@ final class JSBigIntArrayImpl extends JSIntArrayImpl {
JSBigIntArrayImpl(super._ref);

@override
@pragma("wasm:prefer-inline")
int operator [](int index) {
IndexError.check(index, length);
return js.JS<int>('(o, i) => o[i]', toExternRef, index.toDouble()).toInt();
}

@override
@pragma("wasm:prefer-inline")
void operator []=(int index, int value) {
IndexError.check(index, length);
js.JS<void>('(o, i, v) => o[i] = v', toExternRef, index.toDouble(), value);
Expand Down Expand Up @@ -603,12 +609,14 @@ final class JSFloatArrayImpl extends JSArrayBufferViewImpl
JSFloatArrayImpl(super._ref);

@override
@pragma("wasm:prefer-inline")
double operator [](int index) {
IndexError.check(index, length);
return js.JS<double>('(o, i) => o[i]', toExternRef, index.toDouble());
}

@override
@pragma("wasm:prefer-inline")
void operator []=(int index, double value) {
IndexError.check(index, length);
js.JS<void>('(o, i, v) => o[i] = v', toExternRef, index.toDouble(),
Expand Down Expand Up @@ -732,6 +740,7 @@ final class JSFloat32x4ArrayImpl
int get length => _storage.length ~/ 4;

@override
@pragma("wasm:prefer-inline")
Float32x4 operator [](int index) {
IndexError.check(index, length);
double _x = _storage[(index * 4) + 0];
Expand All @@ -742,6 +751,7 @@ final class JSFloat32x4ArrayImpl
}

@override
@pragma("wasm:prefer-inline")
void operator []=(int index, Float32x4 value) {
IndexError.check(index, length);
_storage[(index * 4) + 0] = value.x;
Expand Down Expand Up @@ -782,6 +792,7 @@ final class JSFloat64x2ArrayImpl
int get length => _storage.length ~/ 2;

@override
@pragma("wasm:prefer-inline")
Float64x2 operator [](int index) {
IndexError.check(index, length);
double _x = _storage[(index * 2) + 0];
Expand All @@ -790,6 +801,7 @@ final class JSFloat64x2ArrayImpl
}

@override
@pragma("wasm:prefer-inline")
void operator []=(int index, Float64x2 value) {
IndexError.check(index, length);
_storage[(index * 2) + 0] = value.x;
Expand Down

0 comments on commit c5dd320

Please sign in to comment.