| 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 // Immutable map class for compiler generated map literals. | 4 // Immutable map class for compiler generated map literals. |
| 5 | 5 |
| 6 class ImmutableMap<K, V> implements Map<K, V> { | 6 class ImmutableMap<K, V> implements Map<K, V> { |
| 7 final _ImmutableArray _kvPairs; | 7 final _ImmutableList _kvPairs; |
| 8 | 8 |
| 9 const ImmutableMap._create(_ImmutableArray keyValuePairs) | 9 const ImmutableMap._create(_ImmutableList keyValuePairs) |
| 10 : _kvPairs = keyValuePairs; | 10 : _kvPairs = keyValuePairs; |
| 11 | 11 |
| 12 | 12 |
| 13 V operator [](Object key) { | 13 V operator [](Object key) { |
| 14 // TODO(hausner): Since the keys are sorted, we could do a binary | 14 // TODO(hausner): Since the keys are sorted, we could do a binary |
| 15 // search. But is it worth it? | 15 // search. But is it worth it? |
| 16 for (int i = 0; i < _kvPairs.length - 1; i += 2) { | 16 for (int i = 0; i < _kvPairs.length - 1; i += 2) { |
| 17 if (key == _kvPairs[i]) { | 17 if (key == _kvPairs[i]) { |
| 18 return _kvPairs[i+1]; | 18 return _kvPairs[i+1]; |
| 19 } | 19 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 _current = _map._kvPairs[newIndex * 2 + 1]; | 138 _current = _map._kvPairs[newIndex * 2 + 1]; |
| 139 return true; | 139 return true; |
| 140 } | 140 } |
| 141 _current = null; | 141 _current = null; |
| 142 _index = _map.length; | 142 _index = _map.length; |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 E get current => _current; | 146 E get current => _current; |
| 147 } | 147 } |
| OLD | NEW |