js_runtime: Fix bit mask to match comments
The constant
0x3ffffff
should have been
0x3fffffff
Change-Id: Idc63745bf0527b487a16528a9bce5b048535d41f
Reviewed-on: https://dart-review.googlesource.com/c/89044
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/sdk/lib/_internal/js_runtime/lib/collection_patch.dart b/sdk/lib/_internal/js_runtime/lib/collection_patch.dart
index 7138c65..95e7a7a 100644
--- a/sdk/lib/_internal/js_runtime/lib/collection_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/collection_patch.dart
@@ -21,6 +21,8 @@
const _USE_ES6_MAPS = const bool.fromEnvironment("dart2js.use.es6.maps");
+const int _mask30 = 0x3fffffff; // Low 30 bits.
+
@patch
class HashMap<K, V> {
@patch
@@ -306,14 +308,14 @@
// Only treat unsigned 30-bit integers as numeric keys. This way,
// we avoid converting them to strings when we use them as keys in
// the JavaScript hash table object.
- return key is num && JS('bool', '(# & 0x3ffffff) === #', key, key);
+ return key is num && JS('bool', '(# & #) === #', key, _mask30, key);
}
int _computeHashCode(var key) {
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
// would be to throw an exception if the hash code isn't a number.
- return JS('int', '# & 0x3ffffff', key.hashCode);
+ return JS('int', '# & #', key.hashCode, _mask30);
}
static bool _hasTableEntry(var table, var key) {
@@ -382,7 +384,7 @@
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
// would be to throw an exception if the hash code isn't a number.
- return JS('int', '# & 0x3ffffff', identityHashCode(key));
+ return JS('int', '# & #', identityHashCode(key), _mask30);
}
int _findBucketIndex(var bucket, var key) {
@@ -426,7 +428,7 @@
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
// would be to throw an exception if the hash code isn't a number.
- return JS('int', '# & 0x3ffffff', _hashCode(key));
+ return JS('int', '# & #', _hashCode(key), _mask30);
}
int _findBucketIndex(var bucket, var key) {
@@ -576,7 +578,7 @@
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
// would be to throw an exception if the hash code isn't a number.
- return JS('int', '# & 0x3ffffff', identityHashCode(key));
+ return JS('int', '# & #', identityHashCode(key), _mask30);
}
int internalFindBucketIndex(var bucket, var key) {
@@ -669,7 +671,7 @@
// always unboxed (Smi) values. Modification detection will be missed if you
// make exactly some multiple of 2^30 modifications between advances of an
// iterator.
- _modifications = (_modifications + 1) & 0x3ffffff;
+ _modifications = _mask30 & (_modifications + 1);
}
}
@@ -779,7 +781,7 @@
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
// would be to throw an exception if the hash code isn't a number.
- return JS('int', '# & 0x3ffffff', _hashCode(key));
+ return JS('int', '# & #', _hashCode(key), _mask30);
}
int internalFindBucketIndex(var bucket, var key) {
@@ -1050,7 +1052,7 @@
// way, we avoid converting them to strings when we use them as
// keys in the JavaScript hash table object.
return element is num &&
- JS('bool', '(# & 0x3ffffff) === #', element, element);
+ JS('bool', '(# & #) === #', element, _mask30, element);
}
int _computeHashCode(var element) {
@@ -1058,7 +1060,7 @@
// issues with problematic elements like '__proto__'. Another
// option would be to throw an exception if the hash code isn't a
// number.
- return JS('int', '# & 0x3ffffff', element.hashCode);
+ return JS('int', '# & #', element.hashCode, _mask30);
}
static bool _hasTableEntry(var table, var key) {
@@ -1114,7 +1116,7 @@
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
// would be to throw an exception if the hash code isn't a number.
- return JS('int', '# & 0x3ffffff', identityHashCode(key));
+ return JS('int', '# & #', identityHashCode(key), _mask30);
}
int _findBucketIndex(var bucket, var element) {
@@ -1151,7 +1153,7 @@
// issues with problematic elements like '__proto__'. Another
// option would be to throw an exception if the hash code isn't a
// number.
- return JS('int', '# & 0x3ffffff', _hasher(element));
+ return JS('int', '# & #', _hasher(element), _mask30);
}
bool add(E object) => super._add(object);
@@ -1451,7 +1453,7 @@
// Value cycles after 2^30 modifications. If you keep hold of an
// iterator for that long, you might miss a modification
// detection, and iteration can go sour. Don't do that.
- _modifications = (_modifications + 1) & 0x3ffffff;
+ _modifications = _mask30 & (_modifications + 1);
}
// Create a new cell and link it in as the last one in the list.
@@ -1498,7 +1500,7 @@
// way, we avoid converting them to strings when we use them as
// keys in the JavaScript hash table object.
return element is num &&
- JS('bool', '(# & 0x3ffffff) === #', element, element);
+ JS('bool', '(# & #) === #', element, _mask30, element);
}
int _computeHashCode(var element) {
@@ -1506,7 +1508,7 @@
// issues with problematic elements like '__proto__'. Another
// option would be to throw an exception if the hash code isn't a
// number.
- return JS('int', '# & 0x3ffffff', element.hashCode);
+ return JS('int', '# & #', element.hashCode, _mask30);
}
static _getTableEntry(var table, var key) {
@@ -1559,7 +1561,7 @@
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
// would be to throw an exception if the hash code isn't a number.
- return JS('int', '# & 0x3ffffff', identityHashCode(key));
+ return JS('int', '# & #', identityHashCode(key), _mask30);
}
int _findBucketIndex(var bucket, var element) {
@@ -1600,7 +1602,7 @@
// issues with problematic elements like '__proto__'. Another
// option would be to throw an exception if the hash code isn't a
// number.
- return JS('int', '# & 0x3ffffff', _hasher(element));
+ return JS('int', '# & #', _hasher(element), _mask30);
}
bool add(E element) => super._add(element);