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 abstract class ConstantMap<K, V> implements Map<K, V> { | 7 abstract class ConstantMap<K, V> implements Map<K, V> { |
8 const ConstantMap._(); | 8 const ConstantMap._(); |
9 | 9 |
10 bool get isEmpty => length == 0; | 10 bool get isEmpty => length == 0; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // compiler. It is here to make the uninitialized final fields legal. | 96 // compiler. It is here to make the uninitialized final fields legal. |
97 GeneralConstantMap(this._jsData) : super._(); | 97 GeneralConstantMap(this._jsData) : super._(); |
98 | 98 |
99 // [_jsData] holds a key-value pair list. | 99 // [_jsData] holds a key-value pair list. |
100 final _jsData; | 100 final _jsData; |
101 | 101 |
102 // We cannot create the backing map on creation since hashCode interceptors | 102 // We cannot create the backing map on creation since hashCode interceptors |
103 // have not been defined when constants are created. | 103 // have not been defined when constants are created. |
104 Map<K, V> _getMap() { | 104 Map<K, V> _getMap() { |
105 if (JS('bool', r'!this.$map')) { | 105 if (JS('bool', r'!this.$map')) { |
106 Map backingMap = | 106 Map backingMap = new LinkedHashMap<K, V>(); |
107 new LinkedHashMap<K, V>(equals: identical, hashCode: objectHashCode); | |
108 JS('', r'this.$map = #', fillLiteralMap(_jsData, backingMap)); | 107 JS('', r'this.$map = #', fillLiteralMap(_jsData, backingMap)); |
109 } | 108 } |
110 return JS('Map', r'this.$map'); | 109 return JS('Map', r'this.$map'); |
111 } | 110 } |
112 | 111 |
113 bool containsValue(V needle) { | 112 bool containsValue(V needle) { |
114 return _getMap().containsValue(needle); | 113 return _getMap().containsValue(needle); |
115 } | 114 } |
116 | 115 |
117 bool containsKey(Object key) { | 116 bool containsKey(Object key) { |
(...skipping 11 matching lines...) Expand all Loading... |
129 Iterable<K> get keys { | 128 Iterable<K> get keys { |
130 return _getMap().keys; | 129 return _getMap().keys; |
131 } | 130 } |
132 | 131 |
133 Iterable<V> get values { | 132 Iterable<V> get values { |
134 return _getMap().values; | 133 return _getMap().values; |
135 } | 134 } |
136 | 135 |
137 int get length => _getMap().length; | 136 int get length => _getMap().length; |
138 } | 137 } |
OLD | NEW |