From aa1e1d09fe2a2c2cc0b88a5a56f1a9010ac05092 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 20 Mar 2014 22:12:43 +0100 Subject: SI-8428 Refactor ConcatIterator Make the head iterator a constructor parameter, for easier construction and implementation of ++. --- bincompat-forward.whitelist.conf | 6 +++++- src/library/scala/collection/Iterator.scala | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bincompat-forward.whitelist.conf b/bincompat-forward.whitelist.conf index 3eba1effc1..a4cbac4887 100644 --- a/bincompat-forward.whitelist.conf +++ b/bincompat-forward.whitelist.conf @@ -139,6 +139,10 @@ filter { { matchName="scala.reflect.api.Internals#ReificationSupportApi.SyntacticPartialFunction" problemName=MissingMethodProblem - } + }, + { + matchName="scala.collection.Iterator#ConcatIterator.this" + problemName=MissingMethodProblem + } ] } diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 3d379bfa95..1b496383a3 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -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)) } } -- cgit v1.2.3