@@ -2,6 +2,8 @@ package scala.compat.java8.converterImpl
2
2
3
3
import scala .annotation .switch
4
4
5
+ import scala .collection .immutable .VectorIterator
6
+
5
7
import scala .compat .java8 .collectionImpl ._
6
8
import scala .compat .java8 .runtime ._
7
9
@@ -13,20 +15,27 @@ import Stepper._
13
15
14
16
private [java8] trait StepsVectorLike [A ] {
15
17
protected def myVector : Vector [A ]
18
+ protected def myVectorIterator : VectorIterator [A ]
19
+ protected def myVectorLength : Int
16
20
protected var index : Int = 32
17
21
protected var data : Array [AnyRef ] = null
18
22
protected var index1 : Int = 32
19
23
protected var data1 : Array [AnyRef ] = null
20
24
protected final def advanceData (iX : Int ): Unit = {
21
25
index1 += 1
22
- if (index >= 32 ) initTo(iX)
26
+ if (index >= 32 ) {
27
+ if (myVector != null ) initTo(iX)
28
+ else initVpTo(iX)
29
+ }
23
30
else {
24
31
data = data1(index1).asInstanceOf [Array [AnyRef ]]
25
32
index = 0
26
33
}
27
34
}
28
35
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 {
30
39
case x if x <= 0x20 =>
31
40
index = iX
32
41
data = CollectionInternals .getDisplay0(myVector)
@@ -52,12 +61,43 @@ private[java8] trait StepsVectorLike[A] {
52
61
data = data1(index1).asInstanceOf [Array [AnyRef ]]
53
62
}
54
63
}
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
+ }
55
93
}
56
94
57
95
private [java8] class StepsAnyVector [A ](underlying : Vector [A ], _i0 : Int , _iN : Int )
58
96
extends StepsLikeIndexed [A , StepsAnyVector [A ]](_i0, _iN)
59
97
with 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
61
101
def next () = if (hasNext()) {
62
102
index += 1
63
103
if (index >= 32 ) advanceData(i0)
@@ -76,7 +116,9 @@ with StepsVectorLike[A] {
76
116
private [java8] class StepsDoubleVector (underlying : Vector [Double ], _i0 : Int , _iN : Int )
77
117
extends StepsDoubleLikeIndexed [StepsDoubleVector ](_i0, _iN)
78
118
with 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
80
122
def nextDouble () = if (hasNext()) {
81
123
index += 1
82
124
if (index >= 32 ) advanceData(i0)
@@ -95,7 +137,9 @@ with StepsVectorLike[Double] {
95
137
private [java8] class StepsIntVector (underlying : Vector [Int ], _i0 : Int , _iN : Int )
96
138
extends StepsIntLikeIndexed [StepsIntVector ](_i0, _iN)
97
139
with 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
99
143
def nextInt () = if (hasNext()) {
100
144
index += 1
101
145
if (index >= 32 ) advanceData(i0)
@@ -114,7 +158,9 @@ with StepsVectorLike[Int] {
114
158
private [java8] class StepsLongVector (underlying : Vector [Long ], _i0 : Int , _iN : Int )
115
159
extends StepsLongLikeIndexed [StepsLongVector ](_i0, _iN)
116
160
with 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
118
164
def nextLong () = if (hasNext()) {
119
165
index += 1
120
166
if (index >= 32 ) advanceData(i0)
0 commit comments