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

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

Issue 11412086: Make 'where' lazy. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Rebase 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
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 5
6 // TODO(srdjan): Use shared array implementation. 6 // TODO(srdjan): Use shared array implementation.
7 class _ObjectArray<E> implements List<E> { 7 class _ObjectArray<E> implements List<E> {
8 8
9 factory _ObjectArray(int length) native "ObjectArray_allocate"; 9 factory _ObjectArray(int length) native "ObjectArray_allocate";
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 void forEach(f(E element)) { 66 void forEach(f(E element)) {
67 Collections.forEach(this, f); 67 Collections.forEach(this, f);
68 } 68 }
69 69
70 Iterable mappedBy(f(E element)) => new MappedIterable(this, f); 70 Iterable mappedBy(f(E element)) => new MappedIterable(this, f);
71 71
72 reduce(initialValue, combine(previousValue, E element)) { 72 reduce(initialValue, combine(previousValue, E element)) {
73 return Collections.reduce(this, initialValue, combine); 73 return Collections.reduce(this, initialValue, combine);
74 } 74 }
75 75
76 Collection<E> where(bool f(E element)) { 76 Iterable<E> where(bool f(E element)) => new FilteredIterable<E>(this, f);
Lasse Reichstein Nielsen 2012/11/20 11:44:57 FilteredIterable => WhereIterable
floitsch 2012/11/28 13:49:38 Done.
77 return Collections.where(this, new _GrowableObjectArray<E>(), f);
Anders Johnsen 2012/11/20 06:32:21 You could clean up Collections as you go on with t
floitsch 2012/11/28 13:49:38 I usually remove the functions there.
78 }
79 77
80 bool every(bool f(E element)) { 78 bool every(bool f(E element)) {
81 return Collections.every(this, f); 79 return Collections.every(this, f);
82 } 80 }
83 81
84 bool some(bool f(E element)) { 82 bool some(bool f(E element)) {
85 return Collections.some(this, f); 83 return Collections.some(this, f);
86 } 84 }
87 85
88 bool get isEmpty { 86 bool get isEmpty {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void forEach(f(E element)) { 209 void forEach(f(E element)) {
212 Collections.forEach(this, f); 210 Collections.forEach(this, f);
213 } 211 }
214 212
215 Iterable mappedBy(f(E element)) => new MappedIterable(this, f); 213 Iterable mappedBy(f(E element)) => new MappedIterable(this, f);
216 214
217 reduce(initialValue, combine(previousValue, E element)) { 215 reduce(initialValue, combine(previousValue, E element)) {
218 return Collections.reduce(this, initialValue, combine); 216 return Collections.reduce(this, initialValue, combine);
219 } 217 }
220 218
221 Collection<E> where(bool f(E element)) { 219 Iterable<E> where(bool f(E element)) => new FilteredIterable<E>(this, f);
222 return Collections.where(this, new _GrowableObjectArray<E>(), f);
223 }
224 220
225 bool every(bool f(E element)) { 221 bool every(bool f(E element)) {
226 return Collections.every(this, f); 222 return Collections.every(this, f);
227 } 223 }
228 224
229 bool some(bool f(E element)) { 225 bool some(bool f(E element)) {
230 return Collections.some(this, f); 226 return Collections.some(this, f);
231 } 227 }
232 228
233 bool get isEmpty { 229 bool get isEmpty {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return _array[_pos]; 315 return _array[_pos];
320 } 316 }
321 // TODO(floitsch): bad error message. 317 // TODO(floitsch): bad error message.
322 throw new StateError("No more elements"); 318 throw new StateError("No more elements");
323 } 319 }
324 320
325 final List<E> _array; 321 final List<E> _array;
326 final int _length; // Cache array length for faster access. 322 final int _length; // Cache array length for faster access.
327 int _pos; 323 int _pos;
328 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698