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

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

Issue 336863008: Make the JSON decoder (parser) create Dart maps lazily (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review feedback. Created 6 years, 5 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 | sdk/lib/_internal/lib/convert_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 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 (_modificationCount + 1) & _MODIFICATION_COUNT_MASK; 167 (_modificationCount + 1) & _MODIFICATION_COUNT_MASK;
168 return entry.value; 168 return entry.value;
169 } 169 }
170 previous = entry; 170 previous = entry;
171 entry = next; 171 entry = next;
172 } 172 }
173 return null; 173 return null;
174 } 174 }
175 175
176 void clear() { 176 void clear() {
177 _elementCount = 0;
178 _buckets = new List(_INITIAL_CAPACITY); 177 _buckets = new List(_INITIAL_CAPACITY);
179 _modificationCount = (_modificationCount + 1) & _MODIFICATION_COUNT_MASK; 178 if (_elementCount > 0) {
179 _elementCount = 0;
180 _modificationCount = (_modificationCount + 1) & _MODIFICATION_COUNT_MASK;
181 }
180 } 182 }
181 183
182 void _removeEntry(_HashMapEntry entry, 184 void _removeEntry(_HashMapEntry entry,
183 _HashMapEntry previousInBucket, 185 _HashMapEntry previousInBucket,
184 int bucketIndex) { 186 int bucketIndex) {
185 if (previousInBucket == null) { 187 if (previousInBucket == null) {
186 _buckets[bucketIndex] = entry.next; 188 _buckets[bucketIndex] = entry.next;
187 } else { 189 } else {
188 previousInBucket.next = entry.next; 190 previousInBucket.next = entry.next;
189 } 191 }
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 668
667 void removeWhere(bool test(E element)) { 669 void removeWhere(bool test(E element)) {
668 _filterWhere(test, true); 670 _filterWhere(test, true);
669 } 671 }
670 672
671 void retainWhere(bool test(E element)) { 673 void retainWhere(bool test(E element)) {
672 _filterWhere(test, false); 674 _filterWhere(test, false);
673 } 675 }
674 676
675 void clear() { 677 void clear() {
676 _elementCount = 0;
677 _buckets = new List(_INITIAL_CAPACITY); 678 _buckets = new List(_INITIAL_CAPACITY);
678 _modificationCount++; 679 if (_elementCount > 0) {
680 _elementCount = 0;
681 _modificationCount = (_modificationCount + 1) & _MODIFICATION_COUNT_MASK;
682 }
679 } 683 }
680 684
681 void _addEntry(E key, int hashCode, int index) { 685 void _addEntry(E key, int hashCode, int index) {
682 _buckets[index] = new _HashSetEntry(key, hashCode, _buckets[index]); 686 _buckets[index] = new _HashSetEntry(key, hashCode, _buckets[index]);
683 int newElements = _elementCount + 1; 687 int newElements = _elementCount + 1;
684 _elementCount = newElements; 688 _elementCount = newElements;
685 int length = _buckets.length; 689 int length = _buckets.length;
686 // If we end up with more than 75% non-empty entries, we 690 // If we end up with more than 75% non-empty entries, we
687 // resize the backing store. 691 // resize the backing store.
688 if ((newElements << 2) > ((length << 1) + length)) _resize(); 692 if ((newElements << 2) > ((length << 1) + length)) _resize();
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 action(entry.key, entry.value); 960 action(entry.key, entry.value);
957 if (modificationCount != _modificationCount) { 961 if (modificationCount != _modificationCount) {
958 throw new ConcurrentModificationError(this); 962 throw new ConcurrentModificationError(this);
959 } 963 }
960 cursor = cursor._nextEntry; 964 cursor = cursor._nextEntry;
961 } 965 }
962 } 966 }
963 967
964 void clear() { 968 void clear() {
965 _nextEntry = _previousEntry = this; 969 _nextEntry = _previousEntry = this;
966 _elementCount = 0;
967 _buckets = new List(_HashMap._INITIAL_CAPACITY); 970 _buckets = new List(_HashMap._INITIAL_CAPACITY);
968 _modificationCount = (_modificationCount + 1) & _MODIFICATION_COUNT_MASK; 971 if (_elementCount > 0) {
972 _elementCount = 0;
973 _modificationCount = (_modificationCount + 1) & _MODIFICATION_COUNT_MASK;
974 }
969 } 975 }
970 976
971 void _addEntry(List buckets, int index, int length, 977 void _addEntry(List buckets, int index, int length,
972 K key, V value, int hashCode) { 978 K key, V value, int hashCode) {
973 _HashMapEntry entry = 979 _HashMapEntry entry =
974 new _LinkedHashMapEntry(key, value, hashCode, buckets[index], 980 new _LinkedHashMapEntry(key, value, hashCode, buckets[index],
975 _previousEntry, this); 981 _previousEntry, this);
976 buckets[index] = entry; 982 buckets[index] = entry;
977 int newElements = _elementCount + 1; 983 int newElements = _elementCount + 1;
978 _elementCount = newElements; 984 _elementCount = newElements;
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 return false; 1246 return false;
1241 } 1247 }
1242 _LinkedHashSetEntry entry = _next; 1248 _LinkedHashSetEntry entry = _next;
1243 _current = entry.key; 1249 _current = entry.key;
1244 _next = entry._nextEntry; 1250 _next = entry._nextEntry;
1245 return true; 1251 return true;
1246 } 1252 }
1247 1253
1248 E get current => _current; 1254 E get current => _current;
1249 } 1255 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/convert_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698