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

Side by Side Diff: sdk/lib/core/iterable.dart

Issue 181543004: Optimize VM JSON parser for memory use. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add more tests. Created 6 years, 9 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * An object that uses an [Iterator] to serve objects one at a time. 8 * An object that uses an [Iterator] to serve objects one at a time.
9 * 9 *
10 * You can iterate over all objects served by an Iterable object 10 * You can iterate over all objects served by an Iterable object
(...skipping 26 matching lines...) Expand all
37 /** 37 /**
38 * Creates an Iterable that generates its elements dynamically. 38 * Creates an Iterable that generates its elements dynamically.
39 * 39 *
40 * The Iterators created by the Iterable count from 40 * The Iterators created by the Iterable count from
41 * zero to [:count - 1:] while iterating, and call [generator] 41 * zero to [:count - 1:] while iterating, and call [generator]
42 * with that index to create the next value. 42 * with that index to create the next value.
43 * 43 *
44 * As an Iterable, [:new Iterable.generate(n, generator)):] is equivalent to 44 * As an Iterable, [:new Iterable.generate(n, generator)):] is equivalent to
45 * [:const [0, ..., n - 1].map(generator):] 45 * [:const [0, ..., n - 1].map(generator):]
46 */ 46 */
47 factory Iterable.generate(int count, E generator(int index)) { 47 const factory Iterable.generate(int count, E generator(int index)) =
48 return new _GeneratorIterable<E>(count, generator); 48 _GeneratorIterable<E>;
49 }
50 49
51 /** 50 /**
52 * Returns an Iterator that iterates over this Iterable object. 51 * Returns an Iterator that iterates over this Iterable object.
53 */ 52 */
54 Iterator<E> get iterator; 53 Iterator<E> get iterator;
55 54
56 /** 55 /**
57 * Returns a lazy [Iterable] where each element [:e:] of `this` is replaced 56 * Returns a lazy [Iterable] where each element [:e:] of `this` is replaced
58 * by the result of [:f(e):]. 57 * by the result of [:f(e):].
59 * 58 *
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 */ 283 */
285 E elementAt(int index); 284 E elementAt(int index);
286 } 285 }
287 286
288 typedef E _Generator<E>(int index); 287 typedef E _Generator<E>(int index);
289 288
290 class _GeneratorIterable<E> extends IterableBase<E> 289 class _GeneratorIterable<E> extends IterableBase<E>
291 implements EfficientLength { 290 implements EfficientLength {
292 final int _count; 291 final int _count;
293 final _Generator<E> _generator; 292 final _Generator<E> _generator;
294 _GeneratorIterable(this._count, this._generator); 293 const _GeneratorIterable(this._count, this._generator);
295 Iterator<E> get iterator => new _GeneratorIterator(_count, _generator); 294 Iterator<E> get iterator => new _GeneratorIterator(_count, _generator);
296 int get length => _count; 295 int get length => _count;
297 } 296 }
298 297
299 class _GeneratorIterator<E> implements Iterator<E> { 298 class _GeneratorIterator<E> implements Iterator<E> {
300 final int _count; 299 final int _count;
301 final _Generator<E> _generator; 300 final _Generator<E> _generator;
302 int _index = 0; 301 int _index = 0;
303 E _current; 302 E _current;
304 303
(...skipping 18 matching lines...) Expand all
323 */ 322 */
324 abstract class BidirectionalIterator<E> implements Iterator<E> { 323 abstract class BidirectionalIterator<E> implements Iterator<E> {
325 /** 324 /**
326 * Move back to the previous element. 325 * Move back to the previous element.
327 * 326 *
328 * Returns true and updates [current] if successful. Returns false 327 * Returns true and updates [current] if successful. Returns false
329 * and sets [current] to null if there is no previous element. 328 * and sets [current] to null if there is no previous element.
330 */ 329 */
331 bool movePrevious(); 330 bool movePrevious();
332 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698