[ddc] Update types in JSArray operations

- Avoid unnecessary type checks.
- Convert comment syntax to actual generic method syntax.
- Cleanup some type Strings from the JS foreign interface.
- Use var on LHS more consistently.

Performance optimizations can be seen in the ArrayLoop
benchmarks with the highest being ArrayLoop.pseudopoly.forEach
with a 34.15% improvement.

These changes also avoid a large performance regression when
we unfork and the array contains legacy or nullable types.

Change-Id: I88e21a7b0d36d9bb9ba1b0e8ba24326f2b2c8229
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140760
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
Nicholas Shahan 2020-03-26 20:12:53 +00:00 committed by commit-bot@chromium.org
parent fe6f3eaf9f
commit a6664e093b
2 changed files with 19 additions and 19 deletions

View file

@ -158,7 +158,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 0; i < end; i++) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
E element = JS('-dynamic', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
// !test() ensures bool conversion in checked mode.
if (!test(element) == removeMatching) {
retained.add(element);
@ -201,7 +201,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 0; i < end; i++) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
var/*=E*/ element = JS('', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
f(element);
if (this.length != end) throw ConcurrentModificationError(this);
}
@ -243,7 +243,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 1; i < length; i++) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
var/*=E*/ element = JS('', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
value = combine(value, element);
if (length != this.length) throw ConcurrentModificationError(this);
}
@ -256,7 +256,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 0; i < length; i++) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
var/*=E*/ element = JS('', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
value = combine(value, element);
if (this.length != length) throw ConcurrentModificationError(this);
}
@ -268,7 +268,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 0; i < end; ++i) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
var/*=E*/ element = JS('', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (test(element)) return element;
if (this.length != end) throw ConcurrentModificationError(this);
}
@ -281,7 +281,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = length - 1; i >= 0; i--) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
var/*=E*/ element = JS('', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (test(element)) return element;
if (length != this.length) {
throw ConcurrentModificationError(this);
@ -298,7 +298,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 0; i < length; i++) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
E element = JS('-dynamic', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (test(element)) {
if (matchFound) {
throw IterableElementError.tooMany();
@ -394,12 +394,12 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
// Use JS to avoid bounds check (the bounds check elimination
// optimzation is too weak). The 'E' type annotation is a store type
// check - we can't rely on iterable, it could be List<dynamic>.
E element = otherList[otherStart + i];
var element = otherList[otherStart + i];
JS('', '#[#] = #', this, start + i, element);
}
} else {
for (int i = 0; i < length; i++) {
E element = otherList[otherStart + i];
var element = otherList[otherStart + i];
JS('', '#[#] = #', this, start + i, element);
}
}
@ -448,7 +448,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 0; i < end; i++) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
var/*=E*/ element = JS('', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (test(element)) return true;
if (this.length != end) throw ConcurrentModificationError(this);
}
@ -460,7 +460,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
for (int i = 0; i < end; i++) {
// TODO(22407): Improve bounds check elimination to allow this JS code to
// be replaced by indexing.
E element = JS('-dynamic', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (!test(element)) return false;
if (this.length != end) throw ConcurrentModificationError(this);
}
@ -526,7 +526,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
bool contains(Object other) {
var length = this.length;
for (int i = 0; i < length; i++) {
E element = JS('Null', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (element == other) return true;
}
return false;
@ -576,7 +576,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
JS<int>('!', '#', index) < 0) {
throw diagnoseIndexError(this, index);
}
return JS('var', '#[#]', this, index);
return JS<E>('', '#[#]', this, index);
}
void operator []=(int index, E value) {

View file

@ -154,7 +154,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
List retained = [];
int end = this.length;
for (int i = 0; i < end; i++) {
var element = JS<E>('-dynamic', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
// !test() ensures bool conversion in checked mode.
if (!test(element) == removeMatching) {
retained.add(element);
@ -282,7 +282,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
E? match = null;
bool matchFound = false;
for (int i = 0; i < length; i++) {
var element = JS<E>('-dynamic', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (test(element)) {
if (matchFound) {
throw IterableElementError.tooMany();
@ -378,12 +378,12 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
// Use JS to avoid bounds check (the bounds check elimination
// optimzation is too weak). The 'E' type annotation is a store type
// check - we can't rely on iterable, it could be List<dynamic>.
E element = otherList[otherStart + i];
var element = otherList[otherStart + i];
JS('', '#[#] = #', this, start + i, element);
}
} else {
for (int i = 0; i < length; i++) {
E element = otherList[otherStart + i];
var element = otherList[otherStart + i];
JS('', '#[#] = #', this, start + i, element);
}
}
@ -440,7 +440,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
bool every(bool Function(E) test) {
int end = this.length;
for (int i = 0; i < end; i++) {
var element = JS<E>('-dynamic', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (!test(element)) return false;
if (this.length != end) throw ConcurrentModificationError(this);
}
@ -507,7 +507,7 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
bool contains(Object? other) {
var length = this.length;
for (int i = 0; i < length; i++) {
E element = JS('Null', '#[#]', this, i);
var element = JS<E>('', '#[#]', this, i);
if (element == other) return true;
}
return false;