Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: tool/input_sdk/patch/collection_patch.dart

Issue 1122313002: Typing fixes to eliminate casts/dcalls (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tool/input_sdk/lib/collection/splay_tree.dart ('k') | tool/input_sdk/patch/core_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Patch file for dart:collection classes. 5 // Patch file for dart:collection classes.
6 import 'dart:_foreign_helper' show JS; 6 import 'dart:_foreign_helper' show JS;
7 import 'dart:_js_helper' show 7 import 'dart:_js_helper' show
8 fillLiteralMap, InternalMap, NoInline, NoThrows, patch; 8 fillLiteralMap, InternalMap, NoInline, NoThrows, patch;
9 9
10 @patch 10 @patch
11 class HashMap<K, V> { 11 class HashMap<K, V> {
12 @patch 12 @patch
13 factory HashMap({ bool equals(K key1, K key2), 13 factory HashMap({ bool equals(K key1, K key2),
14 int hashCode(K key), 14 int hashCode(K key),
15 bool isValidKey(potentialKey) }) { 15 bool isValidKey(Object potentialKey) }) {
16 if (isValidKey == null) { 16 if (isValidKey == null) {
17 if (hashCode == null) { 17 if (hashCode == null) {
18 if (equals == null) { 18 if (equals == null) {
19 return new _HashMap<K, V>(); 19 return new _HashMap<K, V>();
20 } 20 }
21 hashCode = _defaultHashCode; 21 hashCode = _defaultHashCode;
22 } else { 22 } else {
23 if (identical(identityHashCode, hashCode) && 23 if (identical(identityHashCode, hashCode) &&
24 identical(identical, equals)) { 24 identical(identical, equals)) {
25 return new _IdentityHashMap<K, V>(); 25 return new _IdentityHashMap<K, V>();
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 for (int i = 0; i < length; i += 2) { 377 for (int i = 0; i < length; i += 2) {
378 if (identical(JS('var', '#[#]', bucket, i), key)) return i; 378 if (identical(JS('var', '#[#]', bucket, i), key)) return i;
379 } 379 }
380 return -1; 380 return -1;
381 } 381 }
382 } 382 }
383 383
384 class _CustomHashMap<K, V> extends _HashMap<K, V> { 384 class _CustomHashMap<K, V> extends _HashMap<K, V> {
385 final _Equality<K> _equals; 385 final _Equality<K> _equals;
386 final _Hasher<K> _hashCode; 386 final _Hasher<K> _hashCode;
387 final _Predicate _validKey; 387 final _Predicate<Object> _validKey;
388 _CustomHashMap(this._equals, this._hashCode, bool validKey(potentialKey)) 388 _CustomHashMap(this._equals, this._hashCode,
389 bool validKey(Object potentialKey))
389 : _validKey = (validKey != null) ? validKey : ((v) => v is K); 390 : _validKey = (validKey != null) ? validKey : ((v) => v is K);
390 391
391 V operator[](Object key) { 392 V operator[](Object key) {
392 if (!_validKey(key)) return null; 393 if (!_validKey(key)) return null;
393 return super._get(key); 394 return super._get(key);
394 } 395 }
395 396
396 void operator[]=(K key, V value) { 397 void operator[]=(K key, V value) {
397 super._set(key, value); 398 super._set(key, value);
398 } 399 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 return true; 481 return true;
481 } 482 }
482 } 483 }
483 } 484 }
484 485
485 @patch 486 @patch
486 class LinkedHashMap<K, V> { 487 class LinkedHashMap<K, V> {
487 @patch 488 @patch
488 factory LinkedHashMap({ bool equals(K key1, K key2), 489 factory LinkedHashMap({ bool equals(K key1, K key2),
489 int hashCode(K key), 490 int hashCode(K key),
490 bool isValidKey(potentialKey) }) { 491 bool isValidKey(Object potentialKey) }) {
491 if (isValidKey == null) { 492 if (isValidKey == null) {
492 if (hashCode == null) { 493 if (hashCode == null) {
493 if (equals == null) { 494 if (equals == null) {
494 return new _LinkedHashMap<K, V>(); 495 return new _LinkedHashMap<K, V>();
495 } 496 }
496 hashCode = _defaultHashCode; 497 hashCode = _defaultHashCode;
497 } else { 498 } else {
498 if (identical(identityHashCode, hashCode) && 499 if (identical(identityHashCode, hashCode) &&
499 identical(identical, equals)) { 500 identical(identical, equals)) {
500 return new _LinkedIdentityHashMap<K, V>(); 501 return new _LinkedIdentityHashMap<K, V>();
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 LinkedHashMapCell cell = JS('var', '#[#]', bucket, i); 853 LinkedHashMapCell cell = JS('var', '#[#]', bucket, i);
853 if (identical(cell._key, key)) return i; 854 if (identical(cell._key, key)) return i;
854 } 855 }
855 return -1; 856 return -1;
856 } 857 }
857 } 858 }
858 859
859 class _LinkedCustomHashMap<K, V> extends _LinkedHashMap<K, V> { 860 class _LinkedCustomHashMap<K, V> extends _LinkedHashMap<K, V> {
860 final _Equality<K> _equals; 861 final _Equality<K> _equals;
861 final _Hasher<K> _hashCode; 862 final _Hasher<K> _hashCode;
862 final _Predicate _validKey; 863 final _Predicate<Object> _validKey;
863 _LinkedCustomHashMap(this._equals, this._hashCode, 864 _LinkedCustomHashMap(this._equals, this._hashCode,
864 bool validKey(potentialKey)) 865 bool validKey(Object potentialKey))
865 : _validKey = (validKey != null) ? validKey : ((v) => v is K); 866 : _validKey = (validKey != null) ? validKey : ((v) => v is K);
866 867
867 V operator[](Object key) { 868 V operator[](Object key) {
868 if (!_validKey(key)) return null; 869 if (!_validKey(key)) return null;
869 return super._get(key); 870 return super._get(key);
870 } 871 }
871 872
872 void operator[]=(K key, V value) { 873 void operator[]=(K key, V value) {
873 super._set(key, value); 874 super._set(key, value);
874 } 875 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 return true; 965 return true;
965 } 966 }
966 } 967 }
967 } 968 }
968 969
969 @patch 970 @patch
970 class HashSet<E> { 971 class HashSet<E> {
971 @patch 972 @patch
972 factory HashSet({ bool equals(E e1, E e2), 973 factory HashSet({ bool equals(E e1, E e2),
973 int hashCode(E e), 974 int hashCode(E e),
974 bool isValidKey(potentialKey) }) { 975 bool isValidKey(Object potentialKey) }) {
975 if (isValidKey == null) { 976 if (isValidKey == null) {
976 if (hashCode == null) { 977 if (hashCode == null) {
977 if (equals == null) { 978 if (equals == null) {
978 return new _HashSet<E>(); 979 return new _HashSet<E>();
979 } 980 }
980 hashCode = _defaultHashCode; 981 hashCode = _defaultHashCode;
981 } else { 982 } else {
982 if (identical(identityHashCode, hashCode) && 983 if (identical(identityHashCode, hashCode) &&
983 identical(identical, equals)) { 984 identical(identical, equals)) {
984 return new _IdentityHashSet<E>(); 985 return new _IdentityHashSet<E>();
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 for (int i = 0; i < length; i++) { 1294 for (int i = 0; i < length; i++) {
1294 if (identical(JS('var', '#[#]', bucket, i), element)) return i; 1295 if (identical(JS('var', '#[#]', bucket, i), element)) return i;
1295 } 1296 }
1296 return -1; 1297 return -1;
1297 } 1298 }
1298 } 1299 }
1299 1300
1300 class _CustomHashSet<E> extends _HashSet<E> { 1301 class _CustomHashSet<E> extends _HashSet<E> {
1301 _Equality<E> _equality; 1302 _Equality<E> _equality;
1302 _Hasher<E> _hasher; 1303 _Hasher<E> _hasher;
1303 _Predicate _validKey; 1304 _Predicate<Object> _validKey;
1304 _CustomHashSet(this._equality, this._hasher, bool validKey(potentialKey)) 1305 _CustomHashSet(this._equality, this._hasher,
1306 bool validKey(Object potentialKey))
1305 : _validKey = (validKey != null) ? validKey : ((x) => x is E); 1307 : _validKey = (validKey != null) ? validKey : ((x) => x is E);
1306 1308
1307 Set<E> _newSet() => new _CustomHashSet<E>(_equality, _hasher, _validKey); 1309 Set<E> _newSet() => new _CustomHashSet<E>(_equality, _hasher, _validKey);
1308 1310
1309 int _findBucketIndex(var bucket, var element) { 1311 int _findBucketIndex(var bucket, var element) {
1310 if (bucket == null) return -1; 1312 if (bucket == null) return -1;
1311 int length = JS('int', '#.length', bucket); 1313 int length = JS('int', '#.length', bucket);
1312 for (int i = 0; i < length; i++) { 1314 for (int i = 0; i < length; i++) {
1313 if (_equality(JS('var', '#[#]', bucket, i), element)) return i; 1315 if (_equality(JS('var', '#[#]', bucket, i), element)) return i;
1314 } 1316 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 return true; 1371 return true;
1370 } 1372 }
1371 } 1373 }
1372 } 1374 }
1373 1375
1374 @patch 1376 @patch
1375 class LinkedHashSet<E> { 1377 class LinkedHashSet<E> {
1376 @patch 1378 @patch
1377 factory LinkedHashSet({ bool equals(E e1, E e2), 1379 factory LinkedHashSet({ bool equals(E e1, E e2),
1378 int hashCode(E e), 1380 int hashCode(E e),
1379 bool isValidKey(potentialKey) }) { 1381 bool isValidKey(Object potentialKey) }) {
1380 if (isValidKey == null) { 1382 if (isValidKey == null) {
1381 if (hashCode == null) { 1383 if (hashCode == null) {
1382 if (equals == null) { 1384 if (equals == null) {
1383 return new _LinkedHashSet<E>(); 1385 return new _LinkedHashSet<E>();
1384 } 1386 }
1385 hashCode = _defaultHashCode; 1387 hashCode = _defaultHashCode;
1386 } else { 1388 } else {
1387 if (identical(identityHashCode, hashCode) && 1389 if (identical(identityHashCode, hashCode) &&
1388 identical(identical, equals)) { 1390 identical(identical, equals)) {
1389 return new _LinkedIdentityHashSet<E>(); 1391 return new _LinkedIdentityHashSet<E>();
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 LinkedHashSetCell cell = JS('var', '#[#]', bucket, i); 1737 LinkedHashSetCell cell = JS('var', '#[#]', bucket, i);
1736 if (identical(cell._element, element)) return i; 1738 if (identical(cell._element, element)) return i;
1737 } 1739 }
1738 return -1; 1740 return -1;
1739 } 1741 }
1740 } 1742 }
1741 1743
1742 class _LinkedCustomHashSet<E> extends _LinkedHashSet<E> { 1744 class _LinkedCustomHashSet<E> extends _LinkedHashSet<E> {
1743 _Equality<E> _equality; 1745 _Equality<E> _equality;
1744 _Hasher<E> _hasher; 1746 _Hasher<E> _hasher;
1745 _Predicate _validKey; 1747 _Predicate<Object> _validKey;
1746 _LinkedCustomHashSet(this._equality, this._hasher, 1748 _LinkedCustomHashSet(this._equality, this._hasher,
1747 bool validKey(potentialKey)) 1749 bool validKey(Object potentialKey))
1748 : _validKey = (validKey != null) ? validKey : ((x) => x is E); 1750 : _validKey = (validKey != null) ? validKey : ((x) => x is E);
1749 1751
1750 Set<E> _newSet() => 1752 Set<E> _newSet() =>
1751 new _LinkedCustomHashSet<E>(_equality, _hasher, _validKey); 1753 new _LinkedCustomHashSet<E>(_equality, _hasher, _validKey);
1752 1754
1753 int _findBucketIndex(var bucket, var element) { 1755 int _findBucketIndex(var bucket, var element) {
1754 if (bucket == null) return -1; 1756 if (bucket == null) return -1;
1755 int length = JS('int', '#.length', bucket); 1757 int length = JS('int', '#.length', bucket);
1756 for (int i = 0; i < length; i++) { 1758 for (int i = 0; i < length; i++) {
1757 LinkedHashSetCell cell = JS('var', '#[#]', bucket, i); 1759 LinkedHashSetCell cell = JS('var', '#[#]', bucket, i);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 } else if (_cell == null) { 1831 } else if (_cell == null) {
1830 _current = null; 1832 _current = null;
1831 return false; 1833 return false;
1832 } else { 1834 } else {
1833 _current = _cell._element; 1835 _current = _cell._element;
1834 _cell = _cell._next; 1836 _cell = _cell._next;
1835 return true; 1837 return true;
1836 } 1838 }
1837 } 1839 }
1838 } 1840 }
OLDNEW
« no previous file with comments | « tool/input_sdk/lib/collection/splay_tree.dart ('k') | tool/input_sdk/patch/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698