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

Unified Diff: sdk/lib/collection/iterable.dart

Issue 26681002: Add EfficientLength marker interface to some iterabels. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld 408576698