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

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

Issue 11169004: Add "contains" method to Collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed last illegal-access Created 8 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/byte_array.dart ('k') | tests/corelib/collection_to_string_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 4
5 class _GrowableObjectArray<T> implements List<T> { 5 class _GrowableObjectArray<T> implements List<T> {
6 factory _GrowableObjectArray._uninstantiable() { 6 factory _GrowableObjectArray._uninstantiable() {
7 throw const UnsupportedOperationException( 7 throw const UnsupportedOperationException(
8 "GrowableObjectArray can only be allocated by the VM"); 8 "GrowableObjectArray can only be allocated by the VM");
9 } 9 }
10 10
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 160
161 void _grow(int new_length) { 161 void _grow(int new_length) {
162 var new_data = new _ObjectArray<T>(new_length); 162 var new_data = new _ObjectArray<T>(new_length);
163 for (int i = 0; i < length; i++) { 163 for (int i = 0; i < length; i++) {
164 new_data[i] = this[i]; 164 new_data[i] = this[i];
165 } 165 }
166 _setData(new_data); 166 _setData(new_data);
167 } 167 }
168 168
169 /** 169 // Collection interface.
170 * Collection interface. 170
171 */ 171 bool contains(T element) => Collections.contains(this, element);
172 172
173 void forEach(f(T element)) { 173 void forEach(f(T element)) {
174 // TODO(srdjan): Use Collections.forEach(this, f); 174 // TODO(srdjan): Use Collections.forEach(this, f);
175 // Accessing the list directly improves DeltaBlue performance by 25%. 175 // Accessing the list directly improves DeltaBlue performance by 25%.
176 for (int i = 0; i < length; i++) { 176 for (int i = 0; i < length; i++) {
177 f(this[i]); 177 f(this[i]);
178 } 178 }
179 } 179 }
180 180
181 Collection map(f(T element)) { 181 Collection map(f(T element)) {
(...skipping 27 matching lines...) Expand all
209 209
210 void sort([Comparator<T> compare = Comparable.compare]) { 210 void sort([Comparator<T> compare = Comparable.compare]) {
211 DualPivotQuicksort.sort(this, compare); 211 DualPivotQuicksort.sort(this, compare);
212 } 212 }
213 213
214 String toString() { 214 String toString() {
215 return Collections.collectionToString(this); 215 return Collections.collectionToString(this);
216 } 216 }
217 217
218 Iterator<T> iterator() { 218 Iterator<T> iterator() {
219 return new VariableSizeArrayIterator<T>(this); 219 return new SequenceIterator<T>(this);
220 } 220 }
221 } 221 }
222
223
224 // Iterator for arrays with variable size.
225 class VariableSizeArrayIterator<T> implements Iterator<T> {
226 VariableSizeArrayIterator(_GrowableObjectArray<T> array)
227 : _array = array, _pos = 0 {
228 }
229
230 bool hasNext() {
231 return _array.length > _pos;
232 }
233
234 T next() {
235 if (!hasNext()) {
236 throw const NoMoreElementsException();
237 }
238 return _array[_pos++];
239 }
240
241 final _GrowableObjectArray<T> _array;
242 int _pos;
243 }
OLDNEW
« no previous file with comments | « runtime/lib/byte_array.dart ('k') | tests/corelib/collection_to_string_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698