Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: runtime/lib/immutable_map.dart

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/mock.dart ('k') | runtime/tests/vm/dart/isolate_mirror_local_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 _ImmutableArray kvPairs_;
8 8
9 const ImmutableMap._create(_ImmutableArray keyValuePairs) 9 const ImmutableMap._create(_ImmutableArray keyValuePairs)
10 : kvPairs_ = keyValuePairs; 10 : kvPairs_ = keyValuePairs;
(...skipping 17 matching lines...) Expand all
28 int get length { 28 int get length {
29 return kvPairs_.length ~/ 2; 29 return kvPairs_.length ~/ 2;
30 } 30 }
31 31
32 void forEach(void f(K key, V value)) { 32 void forEach(void f(K key, V value)) {
33 for (int i = 0; i < kvPairs_.length; i += 2) { 33 for (int i = 0; i < kvPairs_.length; i += 2) {
34 f(kvPairs_[i], kvPairs_[i+1]); 34 f(kvPairs_[i], kvPairs_[i+1]);
35 } 35 }
36 } 36 }
37 37
38 Collection<K> getKeys() { 38 Collection<K> get keys {
39 int numKeys = length; 39 int numKeys = length;
40 List<K> list = new List<K>(numKeys); 40 List<K> list = new List<K>(numKeys);
41 for (int i = 0; i < numKeys; i++) { 41 for (int i = 0; i < numKeys; i++) {
42 list[i] = kvPairs_[i*2]; 42 list[i] = kvPairs_[i*2];
43 } 43 }
44 return list; 44 return list;
45 } 45 }
46 46
47 Collection<V> getValues() { 47 Collection<V> get values {
48 int numValues = length; 48 int numValues = length;
49 List<V> list = new List<V>(numValues); 49 List<V> list = new List<V>(numValues);
50 for (int i = 0; i < numValues; i++) { 50 for (int i = 0; i < numValues; i++) {
51 list[i] = kvPairs_[i*2 + 1]; 51 list[i] = kvPairs_[i*2 + 1];
52 } 52 }
53 return list; 53 return list;
54 } 54 }
55 55
56 bool containsKey(K key) { 56 bool containsKey(K key) {
57 for (int i = 0; i < kvPairs_.length; i += 2) { 57 for (int i = 0; i < kvPairs_.length; i += 2) {
(...skipping 27 matching lines...) Expand all
85 85
86 V remove(K key) { 86 V remove(K key) {
87 throw new UnsupportedError("Cannot remove from unmodifiable Map"); 87 throw new UnsupportedError("Cannot remove from unmodifiable Map");
88 } 88 }
89 89
90 String toString() { 90 String toString() {
91 return Maps.mapToString(this); 91 return Maps.mapToString(this);
92 } 92 }
93 } 93 }
94 94
OLDNEW
« no previous file with comments | « pkg/unittest/mock.dart ('k') | runtime/tests/vm/dart/isolate_mirror_local_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698