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

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

Issue 15263004: Adding isNotEmpty property to collection and string. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix template generation Created 7 years, 6 months 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 | « runtime/lib/growable_array.dart ('k') | runtime/lib/string_patch.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;
11 11
12 12
13 V operator [](K key) { 13 V operator [](K 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 }
20 } 20 }
21 return null; 21 return null;
22 } 22 }
23 23
24 bool get isEmpty { 24 bool get isEmpty {
25 return kvPairs_.length == 0; 25 return kvPairs_.length == 0;
26 } 26 }
27 27
28 bool get isNotEmpty => !isEmpty;
29
28 int get length { 30 int get length {
29 return kvPairs_.length ~/ 2; 31 return kvPairs_.length ~/ 2;
30 } 32 }
31 33
32 void forEach(void f(K key, V value)) { 34 void forEach(void f(K key, V value)) {
33 for (int i = 0; i < kvPairs_.length; i += 2) { 35 for (int i = 0; i < kvPairs_.length; i += 2) {
34 f(kvPairs_[i], kvPairs_[i+1]); 36 f(kvPairs_[i], kvPairs_[i+1]);
35 } 37 }
36 } 38 }
37 39
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 _current = _map.kvPairs_[newIndex * 2 + 1]; 138 _current = _map.kvPairs_[newIndex * 2 + 1];
137 return true; 139 return true;
138 } 140 }
139 _current = null; 141 _current = null;
140 _index = _map.length; 142 _index = _map.length;
141 return false; 143 return false;
142 } 144 }
143 145
144 E get current => _current; 146 E get current => _current;
145 } 147 }
OLDNEW
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | runtime/lib/string_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698