Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 * A collection of values, or "elements", that can be accessed sequentially. | 8 * A collection of values, or "elements", that can be accessed sequentially. |
| 9 * | 9 * |
| 10 * The elements of the iterable are accessed by getting an [Iterator] | 10 * The elements of the iterable are accessed by getting an [Iterator] |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 329 } |
| 330 return false; | 330 return false; |
| 331 } | 331 } |
| 332 | 332 |
| 333 /** | 333 /** |
| 334 * Creates a [List] containing the elements of this [Iterable]. | 334 * Creates a [List] containing the elements of this [Iterable]. |
| 335 * | 335 * |
| 336 * The elements are in iteration order. | 336 * The elements are in iteration order. |
| 337 * The list is fixed-length if [growable] is false. | 337 * The list is fixed-length if [growable] is false. |
| 338 */ | 338 */ |
| 339 List<E> toList({ bool growable: true }) => | 339 List<E> toList({ bool growable: true }) { |
| 340 new List<E>.from(this, growable: growable); | 340 if (this is! EfficientLength) { |
|
floitsch
2016/05/20 12:46:02
This check is already done in List.from.
| |
| 341 return new List<E>.from(this, growable: growable); | |
| 342 } | |
| 343 return _toListKnownLength(this.length, growable); | |
| 344 } | |
| 345 | |
| 346 /// Converts this Iterable to a list with the given length. | |
| 347 List<E> _toListKnownLength(int length, bool growable) { | |
| 348 List<E> result; | |
| 349 if (growable) { | |
| 350 result = new List<E>()..length = length; | |
| 351 } else { | |
| 352 result = new List<E>(length); | |
| 353 } | |
| 354 int i = 0; | |
| 355 for (var element in this) { | |
| 356 result[i++] = element; | |
| 357 } | |
| 358 if (i != length) { | |
| 359 throw new ConcurrentModificationError(this); | |
| 360 } | |
| 361 return result; | |
| 362 } | |
| 341 | 363 |
| 342 /** | 364 /** |
| 343 * Creates a [Set] containing the same elements as this iterable. | 365 * Creates a [Set] containing the same elements as this iterable. |
| 344 * | 366 * |
| 345 * The set may contain fewer elements than the iterable, | 367 * The set may contain fewer elements than the iterable, |
| 346 * if the iterable contains an element more than once, | 368 * if the iterable contains an element more than once, |
| 347 * or it contains one or more elements that are equal. | 369 * or it contains one or more elements that are equal. |
| 348 * The order of the elements in the set is not guaranteed to be the same | 370 * The order of the elements in the set is not guaranteed to be the same |
| 349 * as for the iterable. | 371 * as for the iterable. |
| 350 */ | 372 */ |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 */ | 659 */ |
| 638 abstract class BidirectionalIterator<E> implements Iterator<E> { | 660 abstract class BidirectionalIterator<E> implements Iterator<E> { |
| 639 /** | 661 /** |
| 640 * Move back to the previous element. | 662 * Move back to the previous element. |
| 641 * | 663 * |
| 642 * Returns true and updates [current] if successful. Returns false | 664 * Returns true and updates [current] if successful. Returns false |
| 643 * and sets [current] to null if there is no previous element. | 665 * and sets [current] to null if there is no previous element. |
| 644 */ | 666 */ |
| 645 bool movePrevious(); | 667 bool movePrevious(); |
| 646 } | 668 } |
| OLD | NEW |