Skip to content

Commit fc67a19

Browse files
rakudramacommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
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>
1 parent a1ff5f7 commit fc67a19

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

sdk/lib/_internal/js_runtime/lib/collection_patch.dart

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import 'dart:_internal' hide Symbol;
2121

2222
const _USE_ES6_MAPS = const bool.fromEnvironment("dart2js.use.es6.maps");
2323

24+
const int _mask30 = 0x3fffffff; // Low 30 bits.
25+
2426
@patch
2527
class HashMap<K, V> {
2628
@patch
@@ -306,14 +308,14 @@ class _HashMap<K, V> extends MapBase<K, V> implements HashMap<K, V> {
306308
// Only treat unsigned 30-bit integers as numeric keys. This way,
307309
// we avoid converting them to strings when we use them as keys in
308310
// the JavaScript hash table object.
309-
return key is num && JS('bool', '(# & 0x3ffffff) === #', key, key);
311+
return key is num && JS('bool', '(# & #) === #', key, _mask30, key);
310312
}
311313

312314
int _computeHashCode(var key) {
313315
// We force the hash codes to be unsigned 30-bit integers to avoid
314316
// issues with problematic keys like '__proto__'. Another option
315317
// would be to throw an exception if the hash code isn't a number.
316-
return JS('int', '# & 0x3ffffff', key.hashCode);
318+
return JS('int', '# & #', key.hashCode, _mask30);
317319
}
318320

319321
static bool _hasTableEntry(var table, var key) {
@@ -382,7 +384,7 @@ class _IdentityHashMap<K, V> extends _HashMap<K, V> {
382384
// We force the hash codes to be unsigned 30-bit integers to avoid
383385
// issues with problematic keys like '__proto__'. Another option
384386
// would be to throw an exception if the hash code isn't a number.
385-
return JS('int', '# & 0x3ffffff', identityHashCode(key));
387+
return JS('int', '# & #', identityHashCode(key), _mask30);
386388
}
387389

388390
int _findBucketIndex(var bucket, var key) {
@@ -426,7 +428,7 @@ class _CustomHashMap<K, V> extends _HashMap<K, V> {
426428
// We force the hash codes to be unsigned 30-bit integers to avoid
427429
// issues with problematic keys like '__proto__'. Another option
428430
// would be to throw an exception if the hash code isn't a number.
429-
return JS('int', '# & 0x3ffffff', _hashCode(key));
431+
return JS('int', '# & #', _hashCode(key), _mask30);
430432
}
431433

432434
int _findBucketIndex(var bucket, var key) {
@@ -576,7 +578,7 @@ class _LinkedIdentityHashMap<K, V> extends JsLinkedHashMap<K, V> {
576578
// We force the hash codes to be unsigned 30-bit integers to avoid
577579
// issues with problematic keys like '__proto__'. Another option
578580
// would be to throw an exception if the hash code isn't a number.
579-
return JS('int', '# & 0x3ffffff', identityHashCode(key));
581+
return JS('int', '# & #', identityHashCode(key), _mask30);
580582
}
581583

582584
int internalFindBucketIndex(var bucket, var key) {
@@ -669,7 +671,7 @@ class _Es6LinkedIdentityHashMap<K, V> extends _LinkedIdentityHashMap<K, V>
669671
// always unboxed (Smi) values. Modification detection will be missed if you
670672
// make exactly some multiple of 2^30 modifications between advances of an
671673
// iterator.
672-
_modifications = (_modifications + 1) & 0x3ffffff;
674+
_modifications = _mask30 & (_modifications + 1);
673675
}
674676
}
675677

@@ -779,7 +781,7 @@ class _LinkedCustomHashMap<K, V> extends JsLinkedHashMap<K, V> {
779781
// We force the hash codes to be unsigned 30-bit integers to avoid
780782
// issues with problematic keys like '__proto__'. Another option
781783
// would be to throw an exception if the hash code isn't a number.
782-
return JS('int', '# & 0x3ffffff', _hashCode(key));
784+
return JS('int', '# & #', _hashCode(key), _mask30);
783785
}
784786

785787
int internalFindBucketIndex(var bucket, var key) {
@@ -1050,15 +1052,15 @@ class _HashSet<E> extends _SetBase<E> implements HashSet<E> {
10501052
// way, we avoid converting them to strings when we use them as
10511053
// keys in the JavaScript hash table object.
10521054
return element is num &&
1053-
JS('bool', '(# & 0x3ffffff) === #', element, element);
1055+
JS('bool', '(# & #) === #', element, _mask30, element);
10541056
}
10551057

10561058
int _computeHashCode(var element) {
10571059
// We force the hash codes to be unsigned 30-bit integers to avoid
10581060
// issues with problematic elements like '__proto__'. Another
10591061
// option would be to throw an exception if the hash code isn't a
10601062
// number.
1061-
return JS('int', '# & 0x3ffffff', element.hashCode);
1063+
return JS('int', '# & #', element.hashCode, _mask30);
10621064
}
10631065

10641066
static bool _hasTableEntry(var table, var key) {
@@ -1114,7 +1116,7 @@ class _IdentityHashSet<E> extends _HashSet<E> {
11141116
// We force the hash codes to be unsigned 30-bit integers to avoid
11151117
// issues with problematic keys like '__proto__'. Another option
11161118
// would be to throw an exception if the hash code isn't a number.
1117-
return JS('int', '# & 0x3ffffff', identityHashCode(key));
1119+
return JS('int', '# & #', identityHashCode(key), _mask30);
11181120
}
11191121

11201122
int _findBucketIndex(var bucket, var element) {
@@ -1151,7 +1153,7 @@ class _CustomHashSet<E> extends _HashSet<E> {
11511153
// issues with problematic elements like '__proto__'. Another
11521154
// option would be to throw an exception if the hash code isn't a
11531155
// number.
1154-
return JS('int', '# & 0x3ffffff', _hasher(element));
1156+
return JS('int', '# & #', _hasher(element), _mask30);
11551157
}
11561158

11571159
bool add(E object) => super._add(object);
@@ -1451,7 +1453,7 @@ class _LinkedHashSet<E> extends _SetBase<E> implements LinkedHashSet<E> {
14511453
// Value cycles after 2^30 modifications. If you keep hold of an
14521454
// iterator for that long, you might miss a modification
14531455
// detection, and iteration can go sour. Don't do that.
1454-
_modifications = (_modifications + 1) & 0x3ffffff;
1456+
_modifications = _mask30 & (_modifications + 1);
14551457
}
14561458

14571459
// Create a new cell and link it in as the last one in the list.
@@ -1498,15 +1500,15 @@ class _LinkedHashSet<E> extends _SetBase<E> implements LinkedHashSet<E> {
14981500
// way, we avoid converting them to strings when we use them as
14991501
// keys in the JavaScript hash table object.
15001502
return element is num &&
1501-
JS('bool', '(# & 0x3ffffff) === #', element, element);
1503+
JS('bool', '(# & #) === #', element, _mask30, element);
15021504
}
15031505

15041506
int _computeHashCode(var element) {
15051507
// We force the hash codes to be unsigned 30-bit integers to avoid
15061508
// issues with problematic elements like '__proto__'. Another
15071509
// option would be to throw an exception if the hash code isn't a
15081510
// number.
1509-
return JS('int', '# & 0x3ffffff', element.hashCode);
1511+
return JS('int', '# & #', element.hashCode, _mask30);
15101512
}
15111513

15121514
static _getTableEntry(var table, var key) {
@@ -1559,7 +1561,7 @@ class _LinkedIdentityHashSet<E> extends _LinkedHashSet<E> {
15591561
// We force the hash codes to be unsigned 30-bit integers to avoid
15601562
// issues with problematic keys like '__proto__'. Another option
15611563
// would be to throw an exception if the hash code isn't a number.
1562-
return JS('int', '# & 0x3ffffff', identityHashCode(key));
1564+
return JS('int', '# & #', identityHashCode(key), _mask30);
15631565
}
15641566

15651567
int _findBucketIndex(var bucket, var element) {
@@ -1600,7 +1602,7 @@ class _LinkedCustomHashSet<E> extends _LinkedHashSet<E> {
16001602
// issues with problematic elements like '__proto__'. Another
16011603
// option would be to throw an exception if the hash code isn't a
16021604
// number.
1603-
return JS('int', '# & 0x3ffffff', _hasher(element));
1605+
return JS('int', '# & #', _hasher(element), _mask30);
16041606
}
16051607

16061608
bool add(E element) => super._add(element);

0 commit comments

Comments
 (0)