Permalink
Browse files

SI-8428 Refactor ConcatIterator

Make the head iterator a constructor parameter, for easier
construction and implementation of ++.
  • Loading branch information...
1 parent 1fa46a5 commit aa1e1d09fe2a2c2cc0b88a5a56f1a9010ac05092 @retronym retronym committed Mar 20, 2014
Showing with 10 additions and 6 deletions.
  1. +5 −1 bincompat-forward.whitelist.conf
  2. +5 −5 src/library/scala/collection/Iterator.scala
@@ -139,6 +139,10 @@ filter {
{
matchName="scala.reflect.api.Internals#ReificationSupportApi.SyntacticPartialFunction"
problemName=MissingMethodProblem
- }
+ },
+ {
+ matchName="scala.collection.Iterator#ConcatIterator.this"
+ problemName=MissingMethodProblem
+ }
]
}
@@ -165,11 +165,11 @@ object Iterator {
/** Avoid stack overflows when applying ++ to lots of iterators by
* flattening the unevaluated iterators out into a vector of closures.
*/
- private[scala] final class ConcatIterator[+A](initial: Vector[() => Iterator[A]]) extends Iterator[A] {
- // current set to null when all iterators are exhausted
- private[this] var current: Iterator[A] = Iterator.empty
+ private[scala] final class ConcatIterator[+A](private[this] var current: Iterator[A], initial: Vector[() => Iterator[A]]) extends Iterator[A] {
+ @deprecated def this(initial: Vector[() => Iterator[A]]) = this(Iterator.empty, initial) // for binary compatibility
private[this] var queue: Vector[() => Iterator[A]] = initial
// Advance current to the next non-empty iterator
+ // current is set to null when all iterators are exhausted
private[this] def advance(): Boolean = {
if (queue.isEmpty) {
current = null
@@ -185,7 +185,7 @@ object Iterator {
def next() = if (hasNext) current.next else Iterator.empty.next
override def ++[B >: A](that: => GenTraversableOnce[B]): Iterator[B] =
- new ConcatIterator((() => current) +: (queue :+ (() => that.toIterator)))
+ new ConcatIterator(current, queue :+ (() => that.toIterator))
}
private[scala] final class JoinIterator[+A](lhs: Iterator[A], that: => GenTraversableOnce[A]) extends Iterator[A] {
@@ -194,7 +194,7 @@ object Iterator {
def next = if (lhs.hasNext) lhs.next else rhs.next
override def ++[B >: A](that: => GenTraversableOnce[B]) =
- new ConcatIterator(Vector(() => this, () => that.toIterator))
+ new ConcatIterator(this, Vector(() => that.toIterator))
}
}

0 comments on commit aa1e1d0

Please sign in to comment.