@@ -14,6 +14,8 @@ package scala.compat.java8.converterImpl
1414
1515import scala .annotation .switch
1616
17+ import scala .collection .immutable .VectorIterator
18+
1719import scala .compat .java8 .collectionImpl ._
1820import scala .compat .java8 .runtime ._
1921
@@ -25,20 +27,27 @@ import Stepper._
2527
2628private [java8] trait StepsVectorLike [A ] {
2729 protected def myVector : Vector [A ]
30+ protected def myVectorIterator : VectorIterator [A ]
31+ protected def myVectorLength : Int
2832 protected var index : Int = 32
2933 protected var data : Array [AnyRef ] = null
3034 protected var index1 : Int = 32
3135 protected var data1 : Array [AnyRef ] = null
3236 protected final def advanceData (iX : Int ): Unit = {
3337 index1 += 1
34- if (index >= 32 ) initTo(iX)
38+ if (index >= 32 ) {
39+ if (myVector != null ) initTo(iX)
40+ else initVpTo(iX)
41+ }
3542 else {
3643 data = data1(index1).asInstanceOf [Array [AnyRef ]]
3744 index = 0
3845 }
3946 }
4047 protected final def initTo (iX : Int ): Unit = {
41- myVector.length match {
48+ // WARNING--initVpTo is an exact copy of this except for the type! If you change one you must change the other!
49+ // (Manually specialized this way for speed.)
50+ myVectorLength match {
4251 case x if x <= 0x20 =>
4352 index = iX
4453 data = CollectionInternals .getDisplay0(myVector)
@@ -64,12 +73,43 @@ private[java8] trait StepsVectorLike[A] {
6473 data = data1(index1).asInstanceOf [Array [AnyRef ]]
6574 }
6675 }
76+ protected final def initVpTo (iX : Int ): Unit = {
77+ // WARNING--this is an exact copy of initTo! If you change one you must change the other!
78+ // (Manually specialized this way for speed.)
79+ myVectorLength match {
80+ case x if x <= 0x20 =>
81+ index = iX
82+ data = CollectionInternals .getDisplay0(myVectorIterator)
83+ case x if x <= 0x400 =>
84+ index1 = iX >>> 5
85+ data1 = CollectionInternals .getDisplay1(myVectorIterator)
86+ index = iX & 0x1F
87+ data = data1(index1).asInstanceOf [Array [AnyRef ]]
88+ case x =>
89+ var N = 0
90+ var dataN : Array [AnyRef ] =
91+ if (x <= 0x8000 ) { N = 2 ; CollectionInternals .getDisplay2(myVectorIterator) }
92+ else if (x <= 0x100000 ) { N = 3 ; CollectionInternals .getDisplay3(myVectorIterator) }
93+ else if (x <= 0x2000000 ) { N = 4 ; CollectionInternals .getDisplay4(myVectorIterator) }
94+ else /* x <= 0x40000000*/ { N = 5 ; CollectionInternals .getDisplay5(myVectorIterator) }
95+ while (N > 2 ) {
96+ dataN = dataN((iX >>> (5 * N ))& 0x1F ).asInstanceOf [Array [AnyRef ]]
97+ N -= 1
98+ }
99+ index1 = (iX >>> 5 ) & 0x1F
100+ data1 = dataN((iX >>> 10 ) & 0x1F ).asInstanceOf [Array [AnyRef ]]
101+ index = iX & 0x1F
102+ data = data1(index1).asInstanceOf [Array [AnyRef ]]
103+ }
104+ }
67105}
68106
69107private [java8] class StepsAnyVector [A ](underlying : Vector [A ], _i0 : Int , _iN : Int )
70108extends StepsLikeIndexed [A , StepsAnyVector [A ]](_i0, _iN)
71109with StepsVectorLike [A ] {
72- protected def myVector = underlying
110+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
111+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
112+ protected val myVectorLength = underlying.length
73113 def next () = if (hasNext()) {
74114 index += 1
75115 if (index >= 32 ) advanceData(i0)
@@ -88,7 +128,9 @@ with StepsVectorLike[A] {
88128private [java8] class StepsDoubleVector (underlying : Vector [Double ], _i0 : Int , _iN : Int )
89129extends StepsDoubleLikeIndexed [StepsDoubleVector ](_i0, _iN)
90130with StepsVectorLike [Double ] {
91- protected def myVector = underlying
131+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
132+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
133+ protected val myVectorLength = underlying.length
92134 def nextDouble () = if (hasNext()) {
93135 index += 1
94136 if (index >= 32 ) advanceData(i0)
@@ -107,7 +149,9 @@ with StepsVectorLike[Double] {
107149private [java8] class StepsIntVector (underlying : Vector [Int ], _i0 : Int , _iN : Int )
108150extends StepsIntLikeIndexed [StepsIntVector ](_i0, _iN)
109151with StepsVectorLike [Int ] {
110- protected def myVector = underlying
152+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
153+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
154+ protected val myVectorLength = underlying.length
111155 def nextInt () = if (hasNext()) {
112156 index += 1
113157 if (index >= 32 ) advanceData(i0)
@@ -126,7 +170,9 @@ with StepsVectorLike[Int] {
126170private [java8] class StepsLongVector (underlying : Vector [Long ], _i0 : Int , _iN : Int )
127171extends StepsLongLikeIndexed [StepsLongVector ](_i0, _iN)
128172with StepsVectorLike [Long ] {
129- protected def myVector = underlying
173+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
174+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
175+ protected val myVectorLength = underlying.length
130176 def nextLong () = if (hasNext()) {
131177 index += 1
132178 if (index >= 32 ) advanceData(i0)
0 commit comments