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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/constant_map.dart

Issue 11664006: Make Map.keys/values Iterables. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Add TODO that map.keys should return a Set. Created 7 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/lib/constant_map.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/constant_map.dart b/sdk/lib/_internal/compiler/implementation/lib/constant_map.dart
index 4cb4049f1ba68e79e5a170cec4fdacf11d0cabcc..fabebbd9409216987699335fed2fef99fe1d1517 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/constant_map.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/constant_map.dart
@@ -30,12 +30,12 @@ class ConstantMap<V> implements Map<String, V> {
_keys.forEach((String key) => f(key, this[key]));
}
- Collection<String> get keys => _keys;
+ Iterable<String> get keys {
+ return new _ConstantMapKeyIterable(this);
+ }
- Collection<V> get values {
- List<V> result = <V>[];
- _keys.forEach((String key) => result.add(this[key]));
- return result;
+ Iterable<V> get values {
+ return new MappedIterable<String, V>(_keys, (String key) => this[key]);
}
bool get isEmpty => length == 0;
@@ -66,3 +66,10 @@ class ConstantProtoMap<V> extends ConstantMap<V> {
return super[key];
}
}
+
+class _ConstantMapKeyIterable extends Iterable<String> {
+ ConstantMap _map;
+ _ConstantMapKeyIterable(this._map);
+
+ Iterator<String> get iterator => _map._keys.iterator;
+}

Powered by Google App Engine
This is Rietveld 408576698