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

Unified Diff: sdk/lib/collection/maps.dart

Issue 1319783003: Add static ensure() methods to unmodifiable views. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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/collection/maps.dart
diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart
index 7945e7ea643411074c5e65769a5870c0733913c7..8d68b5e4651a9497d863645bec66c401d15e5c78 100644
--- a/sdk/lib/collection/maps.dart
+++ b/sdk/lib/collection/maps.dart
@@ -208,8 +208,21 @@ class MapView<K, V> implements Map<K, V> {
* the constructor, except for operations that modify the map.
* Modifying operations throw instead.
*/
-class UnmodifiableMapView<K, V> =
- MapView<K, V> with _UnmodifiableMapMixin<K, V>;
+class UnmodifiableMapView<K, V> extends MapView<K, V>
+ with _UnmodifiableMapMixin<K, V> {
+ /**
+ * Returns a view of [source] that's guaranteed to be unmodifiable.
+ *
+ * If [source] already extends [UnmodifiableMapBase] or [UnmodifiableMapView],
+ * this avoids re-wrapping it.
Lasse Reichstein Nielsen 2015/08/27 07:59:04 Also say that it returns the original object unwra
nweiz 2015/08/27 19:25:37 Done.
+ */
+ static Map ensure(Map source) =>
Lasse Reichstein Nielsen 2015/08/27 07:59:04 Move below constructor, and also don't like name h
nweiz 2015/08/27 19:25:37 Done.
+ source is _UnmodifiableMapMixin || source is ImmutableMap
Lasse Reichstein Nielsen 2015/08/27 07:59:04 What is ImmutableMap? It looks like the VM's cons
nweiz 2015/08/27 19:25:37 Yes, this was intended to handle constant maps. I
+ ? source
+ : new UnmodifiableMapView(source);
+
+ UnmodifiableMapView(Map<K, V> map) : super(map);
+}
/**
* Helper class which implements complex [Map] operations

Powered by Google App Engine
This is Rietveld 408576698