@@ -14,6 +14,8 @@ package scala.compat.java8.converterImpl
14
14
15
15
import scala .annotation .switch
16
16
17
+ import scala .collection .immutable .VectorIterator
18
+
17
19
import scala .compat .java8 .collectionImpl ._
18
20
import scala .compat .java8 .runtime ._
19
21
@@ -25,20 +27,27 @@ import Stepper._
25
27
26
28
private [java8] trait StepsVectorLike [A ] {
27
29
protected def myVector : Vector [A ]
30
+ protected def myVectorIterator : VectorIterator [A ]
31
+ protected def myVectorLength : Int
28
32
protected var index : Int = 32
29
33
protected var data : Array [AnyRef ] = null
30
34
protected var index1 : Int = 32
31
35
protected var data1 : Array [AnyRef ] = null
32
36
protected final def advanceData (iX : Int ): Unit = {
33
37
index1 += 1
34
- if (index >= 32 ) initTo(iX)
38
+ if (index >= 32 ) {
39
+ if (myVector != null ) initTo(iX)
40
+ else initVpTo(iX)
41
+ }
35
42
else {
36
43
data = data1(index1).asInstanceOf [Array [AnyRef ]]
37
44
index = 0
38
45
}
39
46
}
40
47
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 {
42
51
case x if x <= 0x20 =>
43
52
index = iX
44
53
data = CollectionInternals .getDisplay0(myVector)
@@ -64,12 +73,43 @@ private[java8] trait StepsVectorLike[A] {
64
73
data = data1(index1).asInstanceOf [Array [AnyRef ]]
65
74
}
66
75
}
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
+ }
67
105
}
68
106
69
107
private [java8] class StepsAnyVector [A ](underlying : Vector [A ], _i0 : Int , _iN : Int )
70
108
extends StepsLikeIndexed [A , StepsAnyVector [A ]](_i0, _iN)
71
109
with 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
73
113
def next () = if (hasNext()) {
74
114
index += 1
75
115
if (index >= 32 ) advanceData(i0)
@@ -88,7 +128,9 @@ with StepsVectorLike[A] {
88
128
private [java8] class StepsDoubleVector (underlying : Vector [Double ], _i0 : Int , _iN : Int )
89
129
extends StepsDoubleLikeIndexed [StepsDoubleVector ](_i0, _iN)
90
130
with 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
92
134
def nextDouble () = if (hasNext()) {
93
135
index += 1
94
136
if (index >= 32 ) advanceData(i0)
@@ -107,7 +149,9 @@ with StepsVectorLike[Double] {
107
149
private [java8] class StepsIntVector (underlying : Vector [Int ], _i0 : Int , _iN : Int )
108
150
extends StepsIntLikeIndexed [StepsIntVector ](_i0, _iN)
109
151
with 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
111
155
def nextInt () = if (hasNext()) {
112
156
index += 1
113
157
if (index >= 32 ) advanceData(i0)
@@ -126,7 +170,9 @@ with StepsVectorLike[Int] {
126
170
private [java8] class StepsLongVector (underlying : Vector [Long ], _i0 : Int , _iN : Int )
127
171
extends StepsLongLikeIndexed [StepsLongVector ](_i0, _iN)
128
172
with 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
130
176
def nextLong () = if (hasNext()) {
131
177
index += 1
132
178
if (index >= 32 ) advanceData(i0)
0 commit comments