diff options
Diffstat (limited to 'src/library/scala/collection/Iterator.scala')
-rw-r--r-- | src/library/scala/collection/Iterator.scala | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index ff10fb44d7..17bb83e52e 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -12,8 +12,6 @@ package collection import mutable.ArrayBuffer import scala.annotation.migration import immutable.Stream -import scala.collection.generic.CanBuildFrom -import scala.annotation.unchecked.{ uncheckedVariance => uV } /** The `Iterator` object provides various functions for creating specialized iterators. * @@ -521,13 +519,13 @@ trait Iterator[+A] extends TraversableOnce[A] { def collect[B](pf: PartialFunction[A, B]): Iterator[B] = new AbstractIterator[B] { // Manually buffer to avoid extra layer of wrapping with buffered private[this] var hd: A = _ - + // Little state machine to keep track of where we are // Seek = 0; Found = 1; Empty = -1 // Not in vals because scalac won't make them static (@inline def only works with -optimize) // BE REALLY CAREFUL TO KEEP COMMENTS AND NUMBERS IN SYNC! private[this] var status = 0/*Seek*/ - + def hasNext = { while (status == 0/*Seek*/) { if (self.hasNext) { @@ -700,9 +698,9 @@ trait Iterator[+A] extends TraversableOnce[A] { } } } - + val leading = new Leading - + val trailing = new AbstractIterator[A] { private[this] var myLeading = leading /* Status flags meanings: @@ -738,7 +736,7 @@ trait Iterator[+A] extends TraversableOnce[A] { } else Iterator.empty.next() } - + override def toString = "unknown-if-empty iterator" } @@ -772,7 +770,7 @@ trait Iterator[+A] extends TraversableOnce[A] { status = 1 false } - def next() = + def next() = if (hasNext) { if (status == 1) self.next() else { @@ -890,7 +888,7 @@ trait Iterator[+A] extends TraversableOnce[A] { * @usecase def foreach(f: A => Unit): Unit * @inheritdoc */ - def foreach[U](f: A => U) { while (hasNext) f(next()) } + def foreach[U](f: A => U) { while (hasNext) f(next()) } /** Tests whether a predicate holds for all values produced by this iterator. * $mayNotTerminateInf @@ -1325,7 +1323,7 @@ trait Iterator[+A] extends TraversableOnce[A] { */ def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit = { var i = start - val end = start + math.min(len, xs.length - start) + val end = start + math.min(len, xs.length - start) while (i < end && hasNext) { xs(i) = next() i += 1 |