Skip to content

Commit 34d130a

Browse files
committed
Refactoring of TrieIterator to do without early definitions.
1 parent 7d572ef commit 34d130a

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/library/scala/collection/immutable/TrieIterator.scala

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,26 @@ import scala.annotation.tailrec
1818
/** Abandons any pretense of type safety for speed. You can't say I
1919
* didn't try: see r23934.
2020
*/
21-
private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) extends AbstractIterator[T] {
22-
outer =>
21+
private[collection] abstract class TrieIterator[+T](
22+
elems: Array[Iterable[T]],
23+
val initDepth: Int,
24+
val initArrayStack: Array[Array[Iterable[T @uV]]],
25+
val initPosStack: Array[Int],
26+
val initArrayD: Array[Iterable[T @uV]],
27+
val initPosD: Int,
28+
val initSubIter: Iterator[T]) extends AbstractIterator[T] { outer =>
29+
30+
def this(elems: Array[Iterable[T]]) =
31+
this(elems,
32+
initDepth = 0,
33+
initArrayStack = new Array[Array[Iterable[T]]](6),
34+
initPosStack = new Array[Int](6),
35+
initArrayD = elems,
36+
initPosD = 0,
37+
initSubIter = null)
2338

2439
private[immutable] def getElem(x: AnyRef): T
2540

26-
def initDepth = 0
27-
def initArrayStack: Array[Array[Iterable[T @uV]]] = new Array[Array[Iterable[T]]](6)
28-
def initPosStack = new Array[Int](6)
29-
def initArrayD: Array[Iterable[T @uV]] = elems
30-
def initPosD = 0
31-
def initSubIter: Iterator[T] = null // to traverse collision nodes
32-
3341
private[this] var depth = initDepth
3442
private[this] var arrayStack: Array[Array[Iterable[T @uV]]] = initArrayStack
3543
private[this] var posStack = initPosStack
@@ -58,14 +66,13 @@ private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) e
5866
case _ => false
5967
}
6068

61-
final class DupIterator(xs: Array[Iterable[T]]) extends {
62-
override val initDepth = outer.depth
63-
override val initArrayStack: Array[Array[Iterable[T @uV]]] = outer.arrayStack
64-
override val initPosStack = outer.posStack
65-
override val initArrayD: Array[Iterable[T @uV]] = outer.arrayD
66-
override val initPosD = outer.posD
67-
override val initSubIter = outer.subIter
68-
} with TrieIterator[T](xs) {
69+
final class DupIterator(xs: Array[Iterable[T]]) extends TrieIterator[T](xs,
70+
initDepth = outer.depth,
71+
initArrayStack = outer.arrayStack,
72+
initPosStack = outer.posStack,
73+
initArrayD = outer.arrayD,
74+
initPosD = outer.posD,
75+
initSubIter = outer.subIter) {
6976
final override def getElem(x: AnyRef): T = outer.getElem(x)
7077
}
7178

0 commit comments

Comments
 (0)