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

Side by Side Diff: pkg/serialization/lib/src/serialization_helpers.dart

Issue 23513010: Make HashMap constructor a factory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 7 years, 3 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_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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * This contains extra functions and classes useful for implementing 6 * This contains extra functions and classes useful for implementing
7 * serialiation. Some or all of these will be removed once the functionality is 7 * serialiation. Some or all of these will be removed once the functionality is
8 * available in the core library. 8 * available in the core library.
9 */ 9 */
10 library serialization_helpers; 10 library serialization_helpers;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 get hashCode => _value.hashCode; 202 get hashCode => _value.hashCode;
203 get object => _value; 203 get object => _value;
204 } 204 }
205 205
206 /** 206 /**
207 * This provides an identity map. We wrap all the objects in 207 * This provides an identity map. We wrap all the objects in
208 * an [_IdentityMapKey] that compares using the identity of the 208 * an [_IdentityMapKey] that compares using the identity of the
209 * wrapped objects. It also treats equal primitive values as identical 209 * wrapped objects. It also treats equal primitive values as identical
210 * to conserve space. 210 * to conserve space.
211 */ 211 */
212 class IdentityMap<K, V> extends HashMap<K, V> { 212 class IdentityMap<K, V> extends LinkedHashMap<K, V> {
213 // TODO(alanknight): Replace with a system identity-based map once 213 // TODO(alanknight): Replace with a system identity-based map once
214 // one is available. Issue 4161. 214 // one is available. Issue 4161.
215 // TODO(lrn): Replace with identity map when custom hash maps are introduced
216 // (which is soon).
215 217
216 // Check before wrapping because some methods may call others, e.g. on 218 // Check before wrapping because some methods may call others, e.g. on
217 // dart2js putIfAbsent calls containsKey, so without this we wrap forever. 219 // dart2js putIfAbsent calls containsKey, so without this we wrap forever.
218 _wrap(Object key) => 220 _wrap(Object key) =>
219 (key is _IdentityMapKey) ? key : new _IdentityMapKey(key); 221 (key is _IdentityMapKey) ? key : new _IdentityMapKey(key);
220 _unwrap(_IdentityMapKey wrapper) => wrapper.object; 222 _unwrap(_IdentityMapKey wrapper) => wrapper.object;
221 223
222 Iterable<K> get keys => super.keys.map((x) => _unwrap(x)); 224 Iterable<K> get keys => super.keys.map((x) => _unwrap(x));
223 Iterable<V> get values => super.values; 225 Iterable<V> get values => super.values;
224 226
225 void forEach(void f(K key, V value)) { 227 void forEach(void f(K key, V value)) {
226 super.forEach((k, v) => f(_unwrap(k), v)); 228 super.forEach((k, v) => f(_unwrap(k), v));
227 } 229 }
228 230
229 V operator [](K key) => super[_wrap(key)]; 231 V operator [](K key) => super[_wrap(key)];
230 232
231 void operator []=(K key, V value) { 233 void operator []=(K key, V value) {
232 super[_wrap(key)] = value; 234 super[_wrap(key)] = value;
233 } 235 }
234 236
235 V putIfAbsent(K key, Function ifAbsent) => 237 V putIfAbsent(K key, Function ifAbsent) =>
236 super.putIfAbsent(_wrap(key), ifAbsent); 238 super.putIfAbsent(_wrap(key), ifAbsent);
237 239
238 bool containsKey(Object key) => super.containsKey(_wrap(key)); 240 bool containsKey(Object key) => super.containsKey(_wrap(key));
239 241
240 V remove(Object key) => super.remove(_wrap(key)); 242 V remove(Object key) => super.remove(_wrap(key));
241 } 243 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/collection_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698