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

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

Issue 26681002: Add EfficientLength marker interface to some iterabels. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also document Map.length is efficient, while we are at it. Created 7 years, 2 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/collection_patch.dart ('k') | sdk/lib/_collection_dev/iterable.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 _ImmutableList _kvPairs; 7 final _ImmutableList _kvPairs;
8 8
9 const ImmutableMap._create(_ImmutableList keyValuePairs) 9 const ImmutableMap._create(_ImmutableList keyValuePairs)
10 : _kvPairs = keyValuePairs; 10 : _kvPairs = keyValuePairs;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 V remove(Object key) { 78 V remove(Object key) {
79 throw new UnsupportedError("Cannot remove from unmodifiable Map"); 79 throw new UnsupportedError("Cannot remove from unmodifiable Map");
80 } 80 }
81 81
82 String toString() { 82 String toString() {
83 return Maps.mapToString(this); 83 return Maps.mapToString(this);
84 } 84 }
85 } 85 }
86 86
87 class _ImmutableMapKeyIterable<E> extends IterableBase<E> { 87 class _ImmutableMapKeyIterable<E> extends IterableBase<E>
88 implements EfficientLength {
88 final ImmutableMap _map; 89 final ImmutableMap _map;
89 _ImmutableMapKeyIterable(this._map); 90 _ImmutableMapKeyIterable(this._map);
90 91
91 Iterator<E> get iterator { 92 Iterator<E> get iterator {
92 return new _ImmutableMapKeyIterator<E>(_map); 93 return new _ImmutableMapKeyIterator<E>(_map);
93 } 94 }
95
96 int get length => _map.length;
94 } 97 }
95 98
96 class _ImmutableMapValueIterable<E> extends IterableBase<E> { 99 class _ImmutableMapValueIterable<E> extends IterableBase<E>
100 implements EfficientLength {
97 final ImmutableMap _map; 101 final ImmutableMap _map;
98 _ImmutableMapValueIterable(this._map); 102 _ImmutableMapValueIterable(this._map);
99 103
100 Iterator<E> get iterator { 104 Iterator<E> get iterator {
101 return new _ImmutableMapValueIterator<E>(_map); 105 return new _ImmutableMapValueIterator<E>(_map);
102 } 106 }
107
108 int get length => _map.length;
103 } 109 }
104 110
105 class _ImmutableMapKeyIterator<E> implements Iterator<E> { 111 class _ImmutableMapKeyIterator<E> implements Iterator<E> {
106 ImmutableMap _map; 112 ImmutableMap _map;
107 int _index = -1; 113 int _index = -1;
108 E _current; 114 E _current;
109 115
110 _ImmutableMapKeyIterator(this._map); 116 _ImmutableMapKeyIterator(this._map);
111 117
112 bool moveNext() { 118 bool moveNext() {
(...skipping 25 matching lines...) Expand all
138 _current = _map._kvPairs[newIndex * 2 + 1]; 144 _current = _map._kvPairs[newIndex * 2 + 1];
139 return true; 145 return true;
140 } 146 }
141 _current = null; 147 _current = null;
142 _index = _map.length; 148 _index = _map.length;
143 return false; 149 return false;
144 } 150 }
145 151
146 E get current => _current; 152 E get current => _current;
147 } 153 }
OLDNEW
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | sdk/lib/_collection_dev/iterable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698