OLD | NEW |
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 class HashMap<K, V> { | 5 patch class HashMap<K, V> { |
6 /* patch */ factory HashMap({ bool equals(K key1, K key2), | 6 /* patch */ factory HashMap({ bool equals(K key1, K key2), |
7 int hashCode(K key), | 7 int hashCode(K key), |
8 bool isValidKey(potentialKey) }) { | 8 bool isValidKey(potentialKey) }) { |
9 if (isValidKey == null) { | 9 if (isValidKey == null) { |
10 if (hashCode == null) { | 10 if (hashCode == null) { |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 var _previousEntry; | 911 var _previousEntry; |
912 | 912 |
913 /* patch */ factory LinkedHashMap({ bool equals(K key1, K key2), | 913 /* patch */ factory LinkedHashMap({ bool equals(K key1, K key2), |
914 int hashCode(K key), | 914 int hashCode(K key), |
915 bool isValidKey(potentialKey) }) { | 915 bool isValidKey(potentialKey) }) { |
916 if (isValidKey == null) { | 916 if (isValidKey == null) { |
917 if (hashCode == null) { | 917 if (hashCode == null) { |
918 if (equals == null) { | 918 if (equals == null) { |
919 if (_useInternalCached) { | 919 if (_useInternalCached) { |
920 return new _InternalLinkedHashMap<K, V>(); | 920 return new _InternalLinkedHashMap<K, V>(); |
| 921 } else if (_useCompactCached) { |
| 922 return new _CompactLinkedHashMap<K, V>(); |
921 } else { | 923 } else { |
922 return new _LinkedHashMap<K, V>(); | 924 return new _LinkedHashMap<K, V>(); |
923 } | 925 } |
924 } | 926 } |
925 hashCode = _defaultHashCode; | 927 hashCode = _defaultHashCode; |
926 } else { | 928 } else { |
927 if (identical(identityHashCode, hashCode) && | 929 if (identical(identityHashCode, hashCode) && |
928 identical(identical, equals)) { | 930 identical(identical, equals)) { |
929 return new _LinkedIdentityHashMap<K, V>(); | 931 return new _LinkedIdentityHashMap<K, V>(); |
930 } | 932 } |
931 if (equals == null) { | 933 if (equals == null) { |
932 equals = _defaultEquals; | 934 equals = _defaultEquals; |
933 } | 935 } |
934 } | 936 } |
935 } else { | 937 } else { |
936 if (hashCode == null) { | 938 if (hashCode == null) { |
937 hashCode = _defaultHashCode; | 939 hashCode = _defaultHashCode; |
938 } | 940 } |
939 if (equals == null) { | 941 if (equals == null) { |
940 equals = _defaultEquals; | 942 equals = _defaultEquals; |
941 } | 943 } |
942 } | 944 } |
943 return new _LinkedCustomHashMap<K, V>(equals, hashCode, isValidKey); | 945 return new _LinkedCustomHashMap<K, V>(equals, hashCode, isValidKey); |
944 } | 946 } |
945 | 947 |
946 /* patch */ factory LinkedHashMap.identity() = _LinkedIdentityHashMap<K, V>; | 948 /* patch */ factory LinkedHashMap.identity() = _LinkedIdentityHashMap<K, V>; |
947 | 949 |
948 static final bool _useInternalCached = _useInternal; | 950 static final bool _useInternalCached = _useInternal; |
949 static bool get _useInternal native "LinkedHashMap_useInternal"; | 951 static bool get _useInternal native "LinkedHashMap_useInternal"; |
| 952 static final bool _useCompactCached = _useCompact; |
| 953 static bool get _useCompact native "LinkedHashMap_useCompact"; |
950 } | 954 } |
951 | 955 |
952 // Methods that are exactly the same in all three linked hash map variants. | 956 // Methods that are exactly the same in all three linked hash map variants. |
953 abstract class _LinkedHashMapMixin<K, V> implements LinkedHashMap<K, V> { | 957 abstract class _LinkedHashMapMixin<K, V> implements LinkedHashMap<K, V> { |
954 var _nextEntry; | 958 var _nextEntry; |
955 var _previousEntry; | 959 var _previousEntry; |
956 | 960 |
957 | 961 |
958 bool containsValue(Object value) { | 962 bool containsValue(Object value) { |
959 int modificationCount = _modificationCount; | 963 int modificationCount = _modificationCount; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 } | 1060 } |
1057 | 1061 |
1058 | 1062 |
1059 patch class LinkedHashSet<E> { | 1063 patch class LinkedHashSet<E> { |
1060 /* patch */ factory LinkedHashSet({ bool equals(E e1, E e2), | 1064 /* patch */ factory LinkedHashSet({ bool equals(E e1, E e2), |
1061 int hashCode(E e), | 1065 int hashCode(E e), |
1062 bool isValidKey(potentialKey) }) { | 1066 bool isValidKey(potentialKey) }) { |
1063 if (isValidKey == null) { | 1067 if (isValidKey == null) { |
1064 if (hashCode == null) { | 1068 if (hashCode == null) { |
1065 if (equals == null) { | 1069 if (equals == null) { |
1066 return new _LinkedHashSet<E>(); | 1070 if (LinkedHashMap._useCompactCached) { |
| 1071 return new _CompactLinkedHashSet<E>(); |
| 1072 } else { |
| 1073 return new _LinkedHashSet<E>(); |
| 1074 } |
1067 } | 1075 } |
1068 hashCode = _defaultHashCode; | 1076 hashCode = _defaultHashCode; |
1069 } else { | 1077 } else { |
1070 if (identical(identityHashCode, hashCode) && | 1078 if (identical(identityHashCode, hashCode) && |
1071 identical(identical, equals)) { | 1079 identical(identical, equals)) { |
1072 return new _LinkedIdentityHashSet<E>(); | 1080 return new _LinkedIdentityHashSet<E>(); |
1073 } | 1081 } |
1074 if (equals == null) { | 1082 if (equals == null) { |
1075 equals = _defaultEquals; | 1083 equals = _defaultEquals; |
1076 } | 1084 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 return false; | 1277 return false; |
1270 } | 1278 } |
1271 _LinkedHashSetEntry entry = _next; | 1279 _LinkedHashSetEntry entry = _next; |
1272 _current = entry.key; | 1280 _current = entry.key; |
1273 _next = entry._nextEntry; | 1281 _next = entry._nextEntry; |
1274 return true; | 1282 return true; |
1275 } | 1283 } |
1276 | 1284 |
1277 E get current => _current; | 1285 E get current => _current; |
1278 } | 1286 } |
OLD | NEW |