Chromium Code Reviews| Index: sdk/lib/collection/iterable.dart |
| diff --git a/sdk/lib/collection/iterable.dart b/sdk/lib/collection/iterable.dart |
| index 9cbdf897caabe9d6e9ba04664887b3856f1e4660..fa357977db9528d684a0e80048219341e800529c 100644 |
| --- a/sdk/lib/collection/iterable.dart |
| +++ b/sdk/lib/collection/iterable.dart |
| @@ -85,6 +85,7 @@ abstract class IterableMixin<E> implements Iterable<E> { |
| Set<E> toSet() => new Set<E>.from(this); |
| int get length { |
| + assert(this is! EfficientLength); |
| int count = 0; |
| Iterator it = iterator; |
| while (it.moveNext()) { |
| @@ -276,6 +277,7 @@ abstract class IterableBase<E> implements Iterable<E> { |
| Set<E> toSet() => new Set<E>.from(this); |
| int get length { |
| + assert(this is! EfficientLength); |
| int count = 0; |
| Iterator it = iterator; |
| while (it.moveNext()) { |
| @@ -380,3 +382,17 @@ abstract class IterableBase<E> implements Iterable<E> { |
| throw new RangeError.value(index); |
| } |
| } |
| + |
| +/** |
| + * Marker interface for [Iterable] subclasses that have an efficient |
| + * [length] implementation. |
| + */ |
| +abstract class EfficientLength { |
|
floitsch
2013/10/10 13:04:53
Move to _collection-dev.
|
| + /** |
| + * Returns the number of elements in the iterable. |
| + * |
| + * This is an efficient operation that doesn't require iterating through |
| + * the elements. |
| + */ |
| + int get length; |
| +} |