| 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._collection.dev; | 5 part of dart._collection.dev; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An [Iterable] for classes that have efficient [length] and [elementAt]. | 8 * An [Iterable] for classes that have efficient [length] and [elementAt]. |
| 9 * | 9 * |
| 10 * All other methods are implemented in terms of [length] and [elementAt], | 10 * All other methods are implemented in terms of [length] and [elementAt], |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 212 } |
| 213 | 213 |
| 214 Iterable<E> skip(int count) => new SubListIterable(this, count, null); | 214 Iterable<E> skip(int count) => new SubListIterable(this, count, null); |
| 215 | 215 |
| 216 Iterable<E> skipWhile(bool test(E element)) => super.skipWhile(test); | 216 Iterable<E> skipWhile(bool test(E element)) => super.skipWhile(test); |
| 217 | 217 |
| 218 Iterable<E> take(int count) => new SubListIterable(this, 0, count); | 218 Iterable<E> take(int count) => new SubListIterable(this, 0, count); |
| 219 | 219 |
| 220 Iterable<E> takeWhile(bool test(E element)) => super.takeWhile(test); | 220 Iterable<E> takeWhile(bool test(E element)) => super.takeWhile(test); |
| 221 | 221 |
| 222 List<E> toList() { | 222 List<E> toList({ bool growable: false }) { |
| 223 List<E> result = new List(length); | 223 List<E> result; |
| 224 if (growable) { |
| 225 result = new List<E>()..length = length; |
| 226 } else { |
| 227 result = new List<E>(length); |
| 228 } |
| 224 for (int i = 0; i < length; i++) { | 229 for (int i = 0; i < length; i++) { |
| 225 result[i] = elementAt(i); | 230 result[i] = elementAt(i); |
| 226 } | 231 } |
| 227 return result; | 232 return result; |
| 228 } | 233 } |
| 229 | 234 |
| 230 Set<E> toSet() { | 235 Set<E> toSet() { |
| 231 Set<E> result = new Set<E>(); | 236 Set<E> result = new Set<E>(); |
| 232 for (int i = 0; i < length; i++) { | 237 for (int i = 0; i < length; i++) { |
| 233 result.add(elementAt(i)); | 238 result.add(elementAt(i)); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 } | 674 } |
| 670 | 675 |
| 671 Iterable<E> skip(int count) => this; | 676 Iterable<E> skip(int count) => this; |
| 672 | 677 |
| 673 Iterable<E> skipWhile(bool test(E element)) => this; | 678 Iterable<E> skipWhile(bool test(E element)) => this; |
| 674 | 679 |
| 675 Iterable<E> take(int count) => this; | 680 Iterable<E> take(int count) => this; |
| 676 | 681 |
| 677 Iterable<E> takeWhile(bool test(E element)) => this; | 682 Iterable<E> takeWhile(bool test(E element)) => this; |
| 678 | 683 |
| 679 List toList() => <E>[]; | 684 List toList({ bool growable: false }) => growable ? <E>[] : new List<E>(0); |
| 680 | 685 |
| 681 Set toSet() => new Set<E>(); | 686 Set toSet() => new Set<E>(); |
| 682 } | 687 } |
| 683 | 688 |
| 684 /** The always empty iterator. */ | 689 /** The always empty iterator. */ |
| 685 class EmptyIterator<E> implements Iterator<E> { | 690 class EmptyIterator<E> implements Iterator<E> { |
| 686 const EmptyIterator(); | 691 const EmptyIterator(); |
| 687 bool moveNext() => false; | 692 bool moveNext() => false; |
| 688 E get current => null; | 693 E get current => null; |
| 689 } | 694 } |
| 690 | 695 |
| 691 /** An [Iterator] that can move in both directions. */ | 696 /** An [Iterator] that can move in both directions. */ |
| 692 abstract class BidirectionalIterator<T> implements Iterator<T> { | 697 abstract class BidirectionalIterator<T> implements Iterator<T> { |
| 693 bool movePrevious(); | 698 bool movePrevious(); |
| 694 } | 699 } |
| OLD | NEW |