| OLD | NEW |
| 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 part of _js_helper; | 5 part of _js_helper; |
| 6 | 6 |
| 7 class ConstantMapView<K, V> extends UnmodifiableMapView | 7 class ConstantMapView<K, V> extends UnmodifiableMapView implements ConstantMap { |
| 8 implements ConstantMap { | |
| 9 ConstantMapView(Map base) : super(base); | 8 ConstantMapView(Map base) : super(base); |
| 10 } | 9 } |
| 11 | 10 |
| 12 abstract class ConstantMap<K, V> implements Map<K, V> { | 11 abstract class ConstantMap<K, V> implements Map<K, V> { |
| 13 // Used to create unmodifiable maps from other maps. | 12 // Used to create unmodifiable maps from other maps. |
| 14 factory ConstantMap.from(Map other) { | 13 factory ConstantMap.from(Map other) { |
| 15 List keys = other.keys.toList(); | 14 List keys = other.keys.toList(); |
| 16 bool allStrings = true; | 15 bool allStrings = true; |
| 17 for (var k in keys) { | 16 for (var k in keys) { |
| 18 if (k is! String) { | 17 if (k is! String) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 49 | 48 |
| 50 bool get isEmpty => length == 0; | 49 bool get isEmpty => length == 0; |
| 51 | 50 |
| 52 bool get isNotEmpty => !isEmpty; | 51 bool get isNotEmpty => !isEmpty; |
| 53 | 52 |
| 54 String toString() => Maps.mapToString(this); | 53 String toString() => Maps.mapToString(this); |
| 55 | 54 |
| 56 static _throwUnmodifiable() { | 55 static _throwUnmodifiable() { |
| 57 throw new UnsupportedError("Cannot modify unmodifiable Map"); | 56 throw new UnsupportedError("Cannot modify unmodifiable Map"); |
| 58 } | 57 } |
| 58 |
| 59 void operator []=(K key, V val) => _throwUnmodifiable(); | 59 void operator []=(K key, V val) => _throwUnmodifiable(); |
| 60 V putIfAbsent(K key, V ifAbsent()) => _throwUnmodifiable(); | 60 V putIfAbsent(K key, V ifAbsent()) => _throwUnmodifiable(); |
| 61 V remove(K key) => _throwUnmodifiable(); | 61 V remove(K key) => _throwUnmodifiable(); |
| 62 void clear() => _throwUnmodifiable(); | 62 void clear() => _throwUnmodifiable(); |
| 63 void addAll(Map<K, V> other) => _throwUnmodifiable(); | 63 void addAll(Map<K, V> other) => _throwUnmodifiable(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 class ConstantStringMap<K, V> extends ConstantMap<K, V> { | 66 class ConstantStringMap<K, V> extends ConstantMap<K, V> { |
| 67 | |
| 68 // This constructor is not used for actual compile-time constants. | 67 // This constructor is not used for actual compile-time constants. |
| 69 // The instantiation of constant maps is shortcut by the compiler. | 68 // The instantiation of constant maps is shortcut by the compiler. |
| 70 const ConstantStringMap._(this._length, this._jsObject, this._keys) | 69 const ConstantStringMap._(this._length, this._jsObject, this._keys) |
| 71 : super._(); | 70 : super._(); |
| 72 | 71 |
| 73 // TODO(18131): Ensure type inference knows the precise types of the fields. | 72 // TODO(18131): Ensure type inference knows the precise types of the fields. |
| 74 final int _length; | 73 final int _length; |
| 75 // A constant map is backed by a JavaScript object. | 74 // A constant map is backed by a JavaScript object. |
| 76 final _jsObject; | 75 final _jsObject; |
| 77 final List<K> _keys; | 76 final List<K> _keys; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 Iterable<K> get keys { | 182 Iterable<K> get keys { |
| 184 return _getMap().keys; | 183 return _getMap().keys; |
| 185 } | 184 } |
| 186 | 185 |
| 187 Iterable<V> get values { | 186 Iterable<V> get values { |
| 188 return _getMap().values; | 187 return _getMap().values; |
| 189 } | 188 } |
| 190 | 189 |
| 191 int get length => _getMap().length; | 190 int get length => _getMap().length; |
| 192 } | 191 } |
| OLD | NEW |