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

Side by Side Diff: runtime/lib/collection_patch.dart

Issue 915323002: Compact LinkedHashMap/Set implementation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/collection_sources.gypi » ('j') | runtime/lib/compact_hash.dart » ('J')
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 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
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
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 (_useCompactCached) {
Vyacheslav Egorov (Google) 2015/02/12 15:42:40 Any reason why you can't just do LinkedHashMap._us
koda 2015/02/17 17:26:28 Done.
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 }
1077 } 1085 }
1078 } else { 1086 } else {
1079 if (hashCode == null) { 1087 if (hashCode == null) {
1080 hashCode = _defaultHashCode; 1088 hashCode = _defaultHashCode;
1081 } 1089 }
1082 if (equals == null) { 1090 if (equals == null) {
1083 equals = _defaultEquals; 1091 equals = _defaultEquals;
1084 } 1092 }
1085 } 1093 }
1086 return new _LinkedCustomHashSet<E>(equals, hashCode, isValidKey); 1094 return new _LinkedCustomHashSet<E>(equals, hashCode, isValidKey);
1087 } 1095 }
1088 1096
1089 /* patch */ factory LinkedHashSet.identity() = _LinkedIdentityHashSet<E>; 1097 /* patch */ factory LinkedHashSet.identity() = _LinkedIdentityHashSet<E>;
1098
1099 static final bool _useCompactCached = _useCompact;
1100 static bool get _useCompact native "LinkedHashMap_useCompact";
1090 } 1101 }
1091 1102
1092 class _LinkedHashSetEntry extends _HashSetEntry { 1103 class _LinkedHashSetEntry extends _HashSetEntry {
1093 /// Links this element into a double-linked list of elements of a hash set. 1104 /// Links this element into a double-linked list of elements of a hash set.
1094 /// The hash set object itself is used as the head entry of the list, so 1105 /// The hash set object itself is used as the head entry of the list, so
1095 /// the field is typed as "var". 1106 /// the field is typed as "var".
1096 /// Both links are initialized to `this` when the object is created. 1107 /// Both links are initialized to `this` when the object is created.
1097 var _nextEntry; 1108 var _nextEntry;
1098 var _previousEntry; 1109 var _previousEntry;
1099 _LinkedHashSetEntry(var key, int hashCode, _LinkedHashSetEntry next, 1110 _LinkedHashSetEntry(var key, int hashCode, _LinkedHashSetEntry next,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 return false; 1280 return false;
1270 } 1281 }
1271 _LinkedHashSetEntry entry = _next; 1282 _LinkedHashSetEntry entry = _next;
1272 _current = entry.key; 1283 _current = entry.key;
1273 _next = entry._nextEntry; 1284 _next = entry._nextEntry;
1274 return true; 1285 return true;
1275 } 1286 }
1276 1287
1277 E get current => _current; 1288 E get current => _current;
1278 } 1289 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/collection_sources.gypi » ('j') | runtime/lib/compact_hash.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698