| 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 // This class has no constructor. This is on purpose since the instantiation | 7 // This class has no constructor. This is on purpose since the instantiation |
| 8 // is shortcut by the compiler. | 8 // is shortcut by the compiler. |
| 9 class ConstantMap<V> implements Map<String, V> { | 9 class ConstantMap<V> implements Map<String, V> { |
| 10 final int length; | 10 final int length; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 void forEach(void f(String key, V value)) { | 29 void forEach(void f(String key, V value)) { |
| 30 _keys.forEach((String key) => f(key, this[key])); | 30 _keys.forEach((String key) => f(key, this[key])); |
| 31 } | 31 } |
| 32 | 32 |
| 33 Iterable<String> get keys { | 33 Iterable<String> get keys { |
| 34 return new _ConstantMapKeyIterable(this); | 34 return new _ConstantMapKeyIterable(this); |
| 35 } | 35 } |
| 36 | 36 |
| 37 Iterable<V> get values { | 37 Iterable<V> get values { |
| 38 return _keys.map((String key) => this[key]); | 38 // TODO(floitsch): don't wrap the map twice. |
| 39 return keys.mappedBy((String key) => this[key]); |
| 39 } | 40 } |
| 40 | 41 |
| 41 bool get isEmpty => length == 0; | 42 bool get isEmpty => length == 0; |
| 42 | 43 |
| 43 String toString() => Maps.mapToString(this); | 44 String toString() => Maps.mapToString(this); |
| 44 | 45 |
| 45 _throwUnmodifiable() { | 46 _throwUnmodifiable() { |
| 46 throw new UnsupportedError("Cannot modify unmodifiable Map"); | 47 throw new UnsupportedError("Cannot modify unmodifiable Map"); |
| 47 } | 48 } |
| 48 void operator []=(String key, V val) => _throwUnmodifiable(); | 49 void operator []=(String key, V val) => _throwUnmodifiable(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 66 return super[key]; | 67 return super[key]; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 class _ConstantMapKeyIterable extends Iterable<String> { | 71 class _ConstantMapKeyIterable extends Iterable<String> { |
| 71 ConstantMap _map; | 72 ConstantMap _map; |
| 72 _ConstantMapKeyIterable(this._map); | 73 _ConstantMapKeyIterable(this._map); |
| 73 | 74 |
| 74 Iterator<String> get iterator => _map._keys.iterator; | 75 Iterator<String> get iterator => _map._keys.iterator; |
| 75 } | 76 } |
| OLD | NEW |