@@ -21,6 +21,8 @@ import 'dart:_internal' hide Symbol;
21
21
22
22
const _USE_ES6_MAPS = const bool .fromEnvironment ("dart2js.use.es6.maps" );
23
23
24
+ const int _mask30 = 0x3fffffff ; // Low 30 bits.
25
+
24
26
@patch
25
27
class HashMap <K , V > {
26
28
@patch
@@ -306,14 +308,14 @@ class _HashMap<K, V> extends MapBase<K, V> implements HashMap<K, V> {
306
308
// Only treat unsigned 30-bit integers as numeric keys. This way,
307
309
// we avoid converting them to strings when we use them as keys in
308
310
// 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);
310
312
}
311
313
312
314
int _computeHashCode (var key) {
313
315
// We force the hash codes to be unsigned 30-bit integers to avoid
314
316
// issues with problematic keys like '__proto__'. Another option
315
317
// 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 );
317
319
}
318
320
319
321
static bool _hasTableEntry (var table, var key) {
@@ -382,7 +384,7 @@ class _IdentityHashMap<K, V> extends _HashMap<K, V> {
382
384
// We force the hash codes to be unsigned 30-bit integers to avoid
383
385
// issues with problematic keys like '__proto__'. Another option
384
386
// 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 );
386
388
}
387
389
388
390
int _findBucketIndex (var bucket, var key) {
@@ -426,7 +428,7 @@ class _CustomHashMap<K, V> extends _HashMap<K, V> {
426
428
// We force the hash codes to be unsigned 30-bit integers to avoid
427
429
// issues with problematic keys like '__proto__'. Another option
428
430
// 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 );
430
432
}
431
433
432
434
int _findBucketIndex (var bucket, var key) {
@@ -576,7 +578,7 @@ class _LinkedIdentityHashMap<K, V> extends JsLinkedHashMap<K, V> {
576
578
// We force the hash codes to be unsigned 30-bit integers to avoid
577
579
// issues with problematic keys like '__proto__'. Another option
578
580
// 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 );
580
582
}
581
583
582
584
int internalFindBucketIndex (var bucket, var key) {
@@ -669,7 +671,7 @@ class _Es6LinkedIdentityHashMap<K, V> extends _LinkedIdentityHashMap<K, V>
669
671
// always unboxed (Smi) values. Modification detection will be missed if you
670
672
// make exactly some multiple of 2^30 modifications between advances of an
671
673
// iterator.
672
- _modifications = (_modifications + 1 ) & 0x3ffffff ;
674
+ _modifications = _mask30 & (_modifications + 1 );
673
675
}
674
676
}
675
677
@@ -779,7 +781,7 @@ class _LinkedCustomHashMap<K, V> extends JsLinkedHashMap<K, V> {
779
781
// We force the hash codes to be unsigned 30-bit integers to avoid
780
782
// issues with problematic keys like '__proto__'. Another option
781
783
// 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 );
783
785
}
784
786
785
787
int internalFindBucketIndex (var bucket, var key) {
@@ -1050,15 +1052,15 @@ class _HashSet<E> extends _SetBase<E> implements HashSet<E> {
1050
1052
// way, we avoid converting them to strings when we use them as
1051
1053
// keys in the JavaScript hash table object.
1052
1054
return element is num &&
1053
- JS ('bool' , '(# & 0x3ffffff ) === #' , element, element);
1055
+ JS ('bool' , '(# & # ) === #' , element, _mask30 , element);
1054
1056
}
1055
1057
1056
1058
int _computeHashCode (var element) {
1057
1059
// We force the hash codes to be unsigned 30-bit integers to avoid
1058
1060
// issues with problematic elements like '__proto__'. Another
1059
1061
// option would be to throw an exception if the hash code isn't a
1060
1062
// number.
1061
- return JS ('int' , '# & 0x3ffffff ' , element.hashCode);
1063
+ return JS ('int' , '# & # ' , element.hashCode, _mask30 );
1062
1064
}
1063
1065
1064
1066
static bool _hasTableEntry (var table, var key) {
@@ -1114,7 +1116,7 @@ class _IdentityHashSet<E> extends _HashSet<E> {
1114
1116
// We force the hash codes to be unsigned 30-bit integers to avoid
1115
1117
// issues with problematic keys like '__proto__'. Another option
1116
1118
// 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 );
1118
1120
}
1119
1121
1120
1122
int _findBucketIndex (var bucket, var element) {
@@ -1151,7 +1153,7 @@ class _CustomHashSet<E> extends _HashSet<E> {
1151
1153
// issues with problematic elements like '__proto__'. Another
1152
1154
// option would be to throw an exception if the hash code isn't a
1153
1155
// number.
1154
- return JS ('int' , '# & 0x3ffffff ' , _hasher (element));
1156
+ return JS ('int' , '# & # ' , _hasher (element), _mask30 );
1155
1157
}
1156
1158
1157
1159
bool add (E object) => super ._add (object);
@@ -1451,7 +1453,7 @@ class _LinkedHashSet<E> extends _SetBase<E> implements LinkedHashSet<E> {
1451
1453
// Value cycles after 2^30 modifications. If you keep hold of an
1452
1454
// iterator for that long, you might miss a modification
1453
1455
// detection, and iteration can go sour. Don't do that.
1454
- _modifications = (_modifications + 1 ) & 0x3ffffff ;
1456
+ _modifications = _mask30 & (_modifications + 1 );
1455
1457
}
1456
1458
1457
1459
// 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> {
1498
1500
// way, we avoid converting them to strings when we use them as
1499
1501
// keys in the JavaScript hash table object.
1500
1502
return element is num &&
1501
- JS ('bool' , '(# & 0x3ffffff ) === #' , element, element);
1503
+ JS ('bool' , '(# & # ) === #' , element, _mask30 , element);
1502
1504
}
1503
1505
1504
1506
int _computeHashCode (var element) {
1505
1507
// We force the hash codes to be unsigned 30-bit integers to avoid
1506
1508
// issues with problematic elements like '__proto__'. Another
1507
1509
// option would be to throw an exception if the hash code isn't a
1508
1510
// number.
1509
- return JS ('int' , '# & 0x3ffffff ' , element.hashCode);
1511
+ return JS ('int' , '# & # ' , element.hashCode, _mask30 );
1510
1512
}
1511
1513
1512
1514
static _getTableEntry (var table, var key) {
@@ -1559,7 +1561,7 @@ class _LinkedIdentityHashSet<E> extends _LinkedHashSet<E> {
1559
1561
// We force the hash codes to be unsigned 30-bit integers to avoid
1560
1562
// issues with problematic keys like '__proto__'. Another option
1561
1563
// 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 );
1563
1565
}
1564
1566
1565
1567
int _findBucketIndex (var bucket, var element) {
@@ -1600,7 +1602,7 @@ class _LinkedCustomHashSet<E> extends _LinkedHashSet<E> {
1600
1602
// issues with problematic elements like '__proto__'. Another
1601
1603
// option would be to throw an exception if the hash code isn't a
1602
1604
// number.
1603
- return JS ('int' , '# & 0x3ffffff ' , _hasher (element));
1605
+ return JS ('int' , '# & # ' , _hasher (element), _mask30 );
1604
1606
}
1605
1607
1606
1608
bool add (E element) => super ._add (element);
0 commit comments