summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-03-20 22:12:43 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-03-24 10:48:52 +0100
commitaa1e1d09fe2a2c2cc0b88a5a56f1a9010ac05092 (patch)
tree450d3c6fb177472258e56c4c1a153ed2ed43458e
parent1fa46a5a9634f09e4905da2468acf5ea75d6462e (diff)
downloadscala-aa1e1d09fe2a2c2cc0b88a5a56f1a9010ac05092.tar.gz
scala-aa1e1d09fe2a2c2cc0b88a5a56f1a9010ac05092.tar.bz2
scala-aa1e1d09fe2a2c2cc0b88a5a56f1a9010ac05092.zip
SI-8428 Refactor ConcatIterator
Make the head iterator a constructor parameter, for easier construction and implementation of ++.
-rw-r--r--bincompat-forward.whitelist.conf6
-rw-r--r--src/library/scala/collection/Iterator.scala10
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))
}
}