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

Side by Side Diff: frog/utils.dart

Issue 9270048: Lots of frog cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Collection<T> supports most of the ES 5 Array methods, but it's missing 5 // Collection<T> supports most of the ES 5 Array methods, but it's missing
6 // map and reduce. 6 // map and reduce.
7 7
8 // TODO(jmesserly): we might want a version of this that return an iterable, 8 // TODO(jmesserly): we might want a version of this that return an iterable,
9 // however JS, Python and Ruby versions are all eager. 9 // however JS, Python and Ruby versions are all eager.
10 List map(Iterable source, mapper(source)) { 10 List map(Iterable source, mapper(source)) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 /** A copy-on-write [Map] implementation. */ 122 /** A copy-on-write [Map] implementation. */
123 // TODO(jmesserly): A persistent tree-based implementation of Map would be much 123 // TODO(jmesserly): A persistent tree-based implementation of Map would be much
124 // nicer. This is just a quick hack to get things working. 124 // nicer. This is just a quick hack to get things working.
125 class CopyOnWriteMap<K extends Hashable, V> implements HashMap<K, V> { 125 class CopyOnWriteMap<K extends Hashable, V> implements HashMap<K, V> {
126 _SharedBackingMap<K, V> _map; 126 _SharedBackingMap<K, V> _map;
127 127
128 CopyOnWriteMap(): _map = new _SharedBackingMap<K, V>(); 128 CopyOnWriteMap(): _map = new _SharedBackingMap<K, V>();
129 CopyOnWriteMap._wrap(this._map); 129 CopyOnWriteMap._wrap(this._map);
130 factory CopyOnWriteMap.from(Map<K, V> other) { 130 factory CopyOnWriteMap.from(Map<K, V> other) {
131 if (other is CopyOnWriteMap<K, V>) { 131 if (other is CopyOnWriteMap<K, V>) {
132 return other.clone(); 132 return other.dynamic.clone();
133 } 133 }
134 return new CopyOnWriteMap<K, V>._wrap( 134 return new CopyOnWriteMap<K, V>._wrap(
135 new _SharedBackingMap<K, V>.from(other)); 135 new _SharedBackingMap<K, V>.from(other));
136 } 136 }
137 137
138 CopyOnWriteMap<K, V> clone() { 138 CopyOnWriteMap<K, V> clone() {
139 _map.shared++; 139 _map.shared++;
140 return new CopyOnWriteMap<K, V>._wrap(_map); 140 return new CopyOnWriteMap<K, V>._wrap(_map);
141 } 141 }
142 142
(...skipping 27 matching lines...) Expand all
170 // Forwarding methods: 170 // Forwarding methods:
171 V operator [](K key) => _map[key]; 171 V operator [](K key) => _map[key];
172 bool isEmpty() => _map.isEmpty(); 172 bool isEmpty() => _map.isEmpty();
173 int get length() => _map.length; 173 int get length() => _map.length;
174 void forEach(void f(K key, V value)) => _map.forEach(f); 174 void forEach(void f(K key, V value)) => _map.forEach(f);
175 Collection<K> getKeys() => _map.getKeys(); 175 Collection<K> getKeys() => _map.getKeys();
176 Collection<V> getValues() => _map.getValues(); 176 Collection<V> getValues() => _map.getValues();
177 bool containsKey(K key) => _map.containsKey(key); 177 bool containsKey(K key) => _map.containsKey(key);
178 bool containsValue(V value) => _map.containsValue(value); 178 bool containsValue(V value) => _map.containsValue(value);
179 } 179 }
OLDNEW
« frog/gen.dart ('K') | « frog/type.dart ('k') | frog/value.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698