@@ -2,6 +2,8 @@ package scala.compat.java8.converterImpl
22
33import scala .annotation .switch
44
5+ import scala .collection .immutable .VectorIterator
6+
57import scala .compat .java8 .collectionImpl ._
68import scala .compat .java8 .runtime ._
79
@@ -13,20 +15,27 @@ import Stepper._
1315
1416private [java8] trait StepsVectorLike [A ] {
1517 protected def myVector : Vector [A ]
18+ protected def myVectorIterator : VectorIterator [A ]
19+ protected def myVectorLength : Int
1620 protected var index : Int = 32
1721 protected var data : Array [AnyRef ] = null
1822 protected var index1 : Int = 32
1923 protected var data1 : Array [AnyRef ] = null
2024 protected final def advanceData (iX : Int ): Unit = {
2125 index1 += 1
22- if (index >= 32 ) initTo(iX)
26+ if (index >= 32 ) {
27+ if (myVector != null ) initTo(iX)
28+ else initVpTo(iX)
29+ }
2330 else {
2431 data = data1(index1).asInstanceOf [Array [AnyRef ]]
2532 index = 0
2633 }
2734 }
2835 protected final def initTo (iX : Int ): Unit = {
29- myVector.length match {
36+ // WARNING--initVpTo is an exact copy of this except for the type! If you change one you must change the other!
37+ // (Manually specialized this way for speed.)
38+ myVectorLength match {
3039 case x if x <= 0x20 =>
3140 index = iX
3241 data = CollectionInternals .getDisplay0(myVector)
@@ -52,12 +61,43 @@ private[java8] trait StepsVectorLike[A] {
5261 data = data1(index1).asInstanceOf [Array [AnyRef ]]
5362 }
5463 }
64+ protected final def initVpTo (iX : Int ): Unit = {
65+ // WARNING--this is an exact copy of initTo! If you change one you must change the other!
66+ // (Manually specialized this way for speed.)
67+ myVectorLength match {
68+ case x if x <= 0x20 =>
69+ index = iX
70+ data = CollectionInternals .getDisplay0(myVectorIterator)
71+ case x if x <= 0x400 =>
72+ index1 = iX >>> 5
73+ data1 = CollectionInternals .getDisplay1(myVectorIterator)
74+ index = iX & 0x1F
75+ data = data1(index1).asInstanceOf [Array [AnyRef ]]
76+ case x =>
77+ var N = 0
78+ var dataN : Array [AnyRef ] =
79+ if (x <= 0x8000 ) { N = 2 ; CollectionInternals .getDisplay2(myVectorIterator) }
80+ else if (x <= 0x100000 ) { N = 3 ; CollectionInternals .getDisplay3(myVectorIterator) }
81+ else if (x <= 0x2000000 ) { N = 4 ; CollectionInternals .getDisplay4(myVectorIterator) }
82+ else /* x <= 0x40000000*/ { N = 5 ; CollectionInternals .getDisplay5(myVectorIterator) }
83+ while (N > 2 ) {
84+ dataN = dataN((iX >>> (5 * N ))& 0x1F ).asInstanceOf [Array [AnyRef ]]
85+ N -= 1
86+ }
87+ index1 = (iX >>> 5 ) & 0x1F
88+ data1 = dataN((iX >>> 10 ) & 0x1F ).asInstanceOf [Array [AnyRef ]]
89+ index = iX & 0x1F
90+ data = data1(index1).asInstanceOf [Array [AnyRef ]]
91+ }
92+ }
5593}
5694
5795private [java8] class StepsAnyVector [A ](underlying : Vector [A ], _i0 : Int , _iN : Int )
5896extends StepsLikeIndexed [A , StepsAnyVector [A ]](_i0, _iN)
5997with StepsVectorLike [A ] {
60- protected def myVector = underlying
98+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
99+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
100+ protected val myVectorLength = underlying.length
61101 def next () = if (hasNext()) {
62102 index += 1
63103 if (index >= 32 ) advanceData(i0)
@@ -76,7 +116,9 @@ with StepsVectorLike[A] {
76116private [java8] class StepsDoubleVector (underlying : Vector [Double ], _i0 : Int , _iN : Int )
77117extends StepsDoubleLikeIndexed [StepsDoubleVector ](_i0, _iN)
78118with StepsVectorLike [Double ] {
79- protected def myVector = underlying
119+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
120+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
121+ protected val myVectorLength = underlying.length
80122 def nextDouble () = if (hasNext()) {
81123 index += 1
82124 if (index >= 32 ) advanceData(i0)
@@ -95,7 +137,9 @@ with StepsVectorLike[Double] {
95137private [java8] class StepsIntVector (underlying : Vector [Int ], _i0 : Int , _iN : Int )
96138extends StepsIntLikeIndexed [StepsIntVector ](_i0, _iN)
97139with StepsVectorLike [Int ] {
98- protected def myVector = underlying
140+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
141+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
142+ protected val myVectorLength = underlying.length
99143 def nextInt () = if (hasNext()) {
100144 index += 1
101145 if (index >= 32 ) advanceData(i0)
@@ -114,7 +158,9 @@ with StepsVectorLike[Int] {
114158private [java8] class StepsLongVector (underlying : Vector [Long ], _i0 : Int , _iN : Int )
115159extends StepsLongLikeIndexed [StepsLongVector ](_i0, _iN)
116160with StepsVectorLike [Long ] {
117- protected def myVector = underlying
161+ protected val myVector = if (CollectionInternals .getDirt(underlying)) null else underlying
162+ protected val myVectorIterator = if (myVector == null ) underlying.iterator else null
163+ protected val myVectorLength = underlying.length
118164 def nextLong () = if (hasNext()) {
119165 index += 1
120166 if (index >= 32 ) advanceData(i0)
0 commit comments