Index: sdk/lib/internal/iterable.dart |
diff --git a/sdk/lib/internal/iterable.dart b/sdk/lib/internal/iterable.dart |
index 7f6b8917f357d088185aa4d462b139c42d46dd43..25cfe68fc4a2fddea1a2ff3fbca411ce0e69d902 100644 |
--- a/sdk/lib/internal/iterable.dart |
+++ b/sdk/lib/internal/iterable.dart |
@@ -584,22 +584,13 @@ class SkipIterable<E> extends Iterable<E> { |
if (iterable is EfficientLengthIterable) { |
return new EfficientLengthSkipIterable<E>(iterable, count); |
} |
- return new SkipIterable<E>._(iterable, count); |
+ return new SkipIterable<E>._(iterable, _checkCount(count)); |
} |
- SkipIterable._(this._iterable, this._skipCount) { |
- if (_skipCount is! int) { |
- throw new ArgumentError.value(_skipCount, "count is not an integer"); |
- } |
- RangeError.checkNotNegative(_skipCount, "count"); |
- } |
+ SkipIterable._(this._iterable, this._skipCount); |
Iterable<E> skip(int count) { |
- if (_skipCount is! int) { |
- throw new ArgumentError.value(_skipCount, "count is not an integer"); |
- } |
- RangeError.checkNotNegative(_skipCount, "count"); |
- return new SkipIterable<E>._(_iterable, _skipCount + count); |
+ return new SkipIterable<E>._(_iterable, _skipCount + _checkCount(count)); |
} |
Iterator<E> get iterator { |
@@ -609,14 +600,31 @@ class SkipIterable<E> extends Iterable<E> { |
class EfficientLengthSkipIterable<E> extends SkipIterable<E> |
implements EfficientLengthIterable<E> { |
- EfficientLengthSkipIterable(Iterable<E> iterable, int skipCount) |
- : super._(iterable, skipCount); |
+ factory EfficientLengthSkipIterable(Iterable<E> iterable, int count) { |
+ return new EfficientLengthSkipIterable<E>._(iterable, _checkCount(count)); |
+ } |
+ |
+ EfficientLengthSkipIterable._(Iterable<E> iterable, int count) |
+ : super._(iterable, count); |
int get length { |
int length = _iterable.length - _skipCount; |
if (length >= 0) return length; |
return 0; |
} |
+ |
+ Iterable<E> skip(int count) { |
+ return new EfficientLengthSkipIterable<E>._( |
+ _iterable, _skipCount + _checkCount(count)); |
+ } |
+} |
+ |
+int _checkCount(int count) { |
+ if (count is! int) { |
+ throw new ArgumentError.value(count, "count", "is not an integer"); |
+ } |
+ RangeError.checkNotNegative(count, "count"); |
+ return count; |
} |
class SkipIterator<E> extends Iterator<E> { |