OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 ImmutableArray kvPairs_; |
8 | 8 |
9 const ImmutableMap(ImmutableArray keyValuePairs) | 9 const ImmutableMap(ImmutableArray keyValuePairs) |
10 : kvPairs_ = keyValuePairs; | 10 : kvPairs_ = keyValuePairs; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 String toString() { | 90 String toString() { |
91 // TODO(srdjan): Extend text representation. | 91 // TODO(srdjan): Extend text representation. |
92 return "ImmutableMap"; | 92 return "ImmutableMap"; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 class MutableMap { | 97 class MutableMap { |
98 // [elements] contains n key-value pairs. The keys are at position | 98 // [elements] contains n key-value pairs. The keys are at position |
99 // 2*n, the values at position 2*n+1. | 99 // 2*n, the values at position 2*n+1. |
100 static fromLiteral(Array elements) { | 100 static fromLiteral(List elements) { |
101 var map = new LinkedHashMap(); | 101 var map = new LinkedHashMap(); |
102 var len = elements.length; | 102 var len = elements.length; |
103 for (int i = 1; i < len; i += 2) { | 103 for (int i = 1; i < len; i += 2) { |
104 map[elements[i-1]] = elements[i]; | 104 map[elements[i-1]] = elements[i]; |
105 } | 105 } |
106 return map; | 106 return map; |
107 } | 107 } |
108 } | 108 } |
OLD | NEW |