Skip to content

Commit 66756d1

Browse files
committed
Split out steppers for Array, IndexedSeq, LinearSeq, Range, Vector
1 parent 675f2ed commit 66756d1

File tree

6 files changed

+308
-265
lines changed

6 files changed

+308
-265
lines changed

src/main/scala/scala/compat/java8/StepConverters.scala

Lines changed: 0 additions & 265 deletions
Original file line numberDiff line numberDiff line change
@@ -8,120 +8,6 @@ import scala.compat.java8.runtime._
88
package converterImpls {
99
import Stepper._
1010

11-
private[java8] class StepsObjectArray[A <: Object](underlying: Array[A], _i0: Int, _iN: Int)
12-
extends StepsLikeIndexed[A, StepsObjectArray[A]](_i0, _iN) {
13-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
14-
def semiclone(half: Int) = new StepsObjectArray[A](underlying, i0, half)
15-
}
16-
17-
private[java8] class StepsAnyArray[A](underlying: Array[A], _i0: Int, _iN: Int)
18-
extends StepsLikeIndexed[A, StepsAnyArray[A]](_i0, _iN) {
19-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
20-
def semiclone(half: Int) = new StepsAnyArray[A](underlying, i0, half)
21-
}
22-
23-
private[java8] class StepsUnitArray(underlying: Array[Unit], _i0: Int, _iN: Int)
24-
extends StepsLikeIndexed[Unit, StepsUnitArray](_i0, _iN) {
25-
def next() = if (hasNext()) { val j = i0; i0 += 1; () } else throwNSEE
26-
def semiclone(half: Int) = new StepsUnitArray(underlying, i0, half)
27-
}
28-
29-
private[java8] class StepsBoxedBooleanArray(underlying: Array[Boolean], _i0: Int, _iN: Int)
30-
extends StepsLikeIndexed[Boolean, StepsBoxedBooleanArray](_i0, _iN) {
31-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
32-
def semiclone(half: Int) = new StepsBoxedBooleanArray(underlying, i0, half)
33-
}
34-
35-
private[java8] class StepsBoxedByteArray(underlying: Array[Byte], _i0: Int, _iN: Int)
36-
extends StepsLikeIndexed[Byte, StepsBoxedByteArray](_i0, _iN) {
37-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
38-
def semiclone(half: Int) = new StepsBoxedByteArray(underlying, i0, half)
39-
}
40-
41-
private[java8] class StepsBoxedCharArray(underlying: Array[Char], _i0: Int, _iN: Int)
42-
extends StepsLikeIndexed[Char, StepsBoxedCharArray](_i0, _iN) {
43-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
44-
def semiclone(half: Int) = new StepsBoxedCharArray(underlying, i0, half)
45-
}
46-
47-
private[java8] class StepsBoxedShortArray(underlying: Array[Short], _i0: Int, _iN: Int)
48-
extends StepsLikeIndexed[Short, StepsBoxedShortArray](_i0, _iN) {
49-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
50-
def semiclone(half: Int) = new StepsBoxedShortArray(underlying, i0, half)
51-
}
52-
53-
private[java8] class StepsBoxedFloatArray(underlying: Array[Float], _i0: Int, _iN: Int)
54-
extends StepsLikeIndexed[Float, StepsBoxedFloatArray](_i0, _iN) {
55-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
56-
def semiclone(half: Int) = new StepsBoxedFloatArray(underlying, i0, half)
57-
}
58-
59-
private[java8] class StepsDoubleArray(underlying: Array[Double], _i0: Int, _iN: Int)
60-
extends StepsDoubleLikeIndexed[StepsDoubleArray](_i0, _iN) {
61-
def nextDouble() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
62-
def semiclone(half: Int) = new StepsDoubleArray(underlying, i0, half)
63-
}
64-
65-
private[java8] class StepsIntArray(underlying: Array[Int], _i0: Int, _iN: Int)
66-
extends StepsIntLikeIndexed[StepsIntArray](_i0, _iN) {
67-
def nextInt() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
68-
def semiclone(half: Int) = new StepsIntArray(underlying, i0, half)
69-
}
70-
71-
private[java8] class StepsLongArray(underlying: Array[Long], _i0: Int, _iN: Int)
72-
extends StepsLongLikeIndexed[StepsLongArray](_i0, _iN) {
73-
def nextLong() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
74-
def semiclone(half: Int) = new StepsLongArray(underlying, i0, half)
75-
}
76-
77-
private[java8] class StepsAnyIndexedSeq[A](underlying: collection.IndexedSeqLike[A, _], _i0: Int, _iN: Int)
78-
extends StepsLikeIndexed[A, StepsAnyIndexedSeq[A]](_i0, _iN) {
79-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
80-
def semiclone(half: Int) = new StepsAnyIndexedSeq[A](underlying, i0, half)
81-
}
82-
83-
private[java8] class StepsDoubleIndexedSeq[CC <: collection.IndexedSeqLike[Double, _]](underlying: CC, _i0: Int, _iN: Int)
84-
extends StepsDoubleLikeIndexed[StepsDoubleIndexedSeq[CC]](_i0, _iN) {
85-
def nextDouble() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
86-
def semiclone(half: Int) = new StepsDoubleIndexedSeq[CC](underlying, i0, half)
87-
}
88-
89-
private[java8] class StepsIntIndexedSeq[CC <: collection.IndexedSeqLike[Int, _]](underlying: CC, _i0: Int, _iN: Int)
90-
extends StepsIntLikeIndexed[StepsIntIndexedSeq[CC]](_i0, _iN) {
91-
def nextInt() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
92-
def semiclone(half: Int) = new StepsIntIndexedSeq[CC](underlying, i0, half)
93-
}
94-
95-
private[java8] class StepsLongIndexedSeq[CC <: collection.IndexedSeqLike[Long, _]](underlying: CC, _i0: Int, _iN: Int)
96-
extends StepsLongLikeIndexed[StepsLongIndexedSeq[CC]](_i0, _iN) {
97-
def nextLong() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
98-
def semiclone(half: Int) = new StepsLongIndexedSeq[CC](underlying, i0, half)
99-
}
100-
101-
private[java8] class StepsAnyLinearSeq[A, CC >: Null <: collection.LinearSeqLike[A, CC]](_underlying: CC, _maxN: Long)
102-
extends StepsWithTail[A, CC, StepsAnyLinearSeq[A, CC]](_underlying, _maxN) {
103-
protected def myIsEmpty(cc: CC): Boolean = cc.isEmpty
104-
protected def myTailOf(cc: CC): CC = cc.tail
105-
def next() = if (hasNext()) { maxN -= 1; val ans = underlying.head; underlying = underlying.tail; ans } else throwNSEE
106-
def semiclone(half: Int) = new StepsAnyLinearSeq[A, CC](underlying, half)
107-
}
108-
109-
private[java8] class StepsDoubleLinearSeq[CC >: Null <: collection.LinearSeqLike[Double, CC]](_underlying: CC, _maxN: Long)
110-
extends StepsDoubleWithTail[CC, StepsDoubleLinearSeq[CC]](_underlying, _maxN) {
111-
protected def myIsEmpty(cc: CC): Boolean = cc.isEmpty
112-
protected def myTailOf(cc: CC): CC = cc.tail
113-
def nextDouble() = if (hasNext()) { maxN -= 1; val ans = underlying.head; underlying = underlying.tail; ans } else throwNSEE
114-
def semiclone(half: Int) = new StepsDoubleLinearSeq[CC](underlying, half)
115-
}
116-
117-
private[java8] class StepsIntLinearSeq[CC >: Null <: collection.LinearSeqLike[Int, CC]](_underlying: CC, _maxN: Long)
118-
extends StepsIntWithTail[CC, StepsIntLinearSeq[CC]](_underlying, _maxN) {
119-
protected def myIsEmpty(cc: CC): Boolean = cc.isEmpty
120-
protected def myTailOf(cc: CC): CC = cc.tail
121-
def nextInt() = if (hasNext()) { maxN -= 1; val ans = underlying.head; underlying = underlying.tail; ans } else throwNSEE
122-
def semiclone(half: Int) = new StepsIntLinearSeq[CC](underlying, half)
123-
}
124-
12511
private[java8] class StepsAnyIterator[A](_underlying: Iterator[A])
12612
extends StepsLikeIterator[A, StepsAnyIterator[A]](_underlying) {
12713
def semiclone() = new StepsAnyIterator(null)
@@ -146,157 +32,6 @@ package converterImpls {
14632
def nextLong() = if (proxied ne null) proxied.nextStep else underlying.next
14733
}
14834

149-
private[java8] class StepsLongLinearSeq[CC >: Null <: collection.LinearSeqLike[Long, CC]](_underlying: CC, _maxN: Long)
150-
extends StepsLongWithTail[CC, StepsLongLinearSeq[CC]](_underlying, _maxN) {
151-
protected def myIsEmpty(cc: CC): Boolean = cc.isEmpty
152-
protected def myTailOf(cc: CC): CC = cc.tail
153-
def nextLong() = if (hasNext()) { maxN -= 1; val ans = underlying.head; underlying = underlying.tail; ans } else throwNSEE
154-
def semiclone(half: Int) = new StepsLongLinearSeq[CC](underlying, half)
155-
}
156-
157-
private[java8] class StepsIntRange(underlying: Range, _i0: Int, _iN: Int)
158-
extends StepsIntLikeIndexed[StepsIntRange](_i0, _iN) {
159-
def nextInt() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
160-
def semiclone(half: Int) = new StepsIntRange(underlying, i0, half)
161-
}
162-
163-
private[java8] class StepsAnyNumericRange[T](underlying: collection.immutable.NumericRange[T], _i0: Int, _iN: Int)
164-
extends StepsLikeIndexed[T, StepsAnyNumericRange[T]](_i0, _iN) {
165-
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
166-
def semiclone(half: Int) = new StepsAnyNumericRange[T](underlying, i0, half)
167-
}
168-
169-
private[java8] class StepsIntNumericRange(underlying: collection.immutable.NumericRange[Int], _i0: Int, _iN: Int)
170-
extends StepsIntLikeIndexed[StepsIntNumericRange](_i0, _iN) {
171-
def nextInt() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
172-
def semiclone(half: Int) = new StepsIntNumericRange(underlying, i0, half)
173-
}
174-
175-
private[java8] class StepsLongNumericRange(underlying: collection.immutable.NumericRange[Long], _i0: Int, _iN: Int)
176-
extends StepsLongLikeIndexed[StepsLongNumericRange](_i0, _iN) {
177-
def nextLong() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
178-
def semiclone(half: Int) = new StepsLongNumericRange(underlying, i0, half)
179-
}
180-
181-
private[java8] trait StepsVectorLike[A] {
182-
protected def myVector: Vector[A]
183-
protected var index: Int = 32
184-
protected var data: Array[AnyRef] = null
185-
protected var index1: Int = 32
186-
protected var data1: Array[AnyRef] = null
187-
protected final def advanceData(iX: Int) {
188-
index1 += 1
189-
if (index >= 32) initTo(iX)
190-
else {
191-
data = data1(index1).asInstanceOf[Array[AnyRef]]
192-
index = 0
193-
}
194-
}
195-
protected final def initTo(iX: Int) {
196-
myVector.length match {
197-
case x if x <= 0x20 =>
198-
index = iX
199-
data = CollectionInternals.getDisplay0(myVector)
200-
case x if x <= 0x400 =>
201-
index1 = iX >>> 5
202-
data1 = CollectionInternals.getDisplay1(myVector)
203-
index = iX & 0x1F
204-
data = data1(index1).asInstanceOf[Array[AnyRef]]
205-
case x =>
206-
var N = 0
207-
var dataN: Array[AnyRef] =
208-
if (x <= 0x8000) { N = 2; CollectionInternals.getDisplay2(myVector) }
209-
else if (x <= 0x100000) { N = 3; CollectionInternals.getDisplay3(myVector) }
210-
else if (x <= 0x2000000) { N = 4; CollectionInternals.getDisplay4(myVector) }
211-
else /*x <= 0x40000000*/{ N = 5; CollectionInternals.getDisplay5(myVector) }
212-
while (N > 2) {
213-
dataN = dataN((iX >>> (5*N))&0x1F).asInstanceOf[Array[AnyRef]]
214-
N -= 1
215-
}
216-
index1 = (iX >>> 5) & 0x1F
217-
data1 = dataN((iX >>> 10) & 0x1F).asInstanceOf[Array[AnyRef]]
218-
index = iX & 0x1F
219-
data = data1(index1).asInstanceOf[Array[AnyRef]]
220-
}
221-
}
222-
}
223-
224-
private[java8] class StepsAnyVector[A](underlying: Vector[A], _i0: Int, _iN: Int)
225-
extends StepsLikeIndexed[A, StepsAnyVector[A]](_i0, _iN)
226-
with StepsVectorLike[A] {
227-
protected def myVector = underlying
228-
def next() = if (hasNext()) {
229-
index += 1
230-
if (index >= 32) advanceData(i0)
231-
i0 += 1
232-
data(index).asInstanceOf[A]
233-
} else throwNSEE
234-
def semiclone(half: Int) = {
235-
val ans = new StepsAnyVector(underlying, i0, half)
236-
index = 32
237-
index1 = 32
238-
i0 = half
239-
ans
240-
}
241-
}
242-
243-
private[java8] class StepsDoubleVector(underlying: Vector[Double], _i0: Int, _iN: Int)
244-
extends StepsDoubleLikeIndexed[StepsDoubleVector](_i0, _iN)
245-
with StepsVectorLike[Double] {
246-
protected def myVector = underlying
247-
def nextDouble() = if (hasNext()) {
248-
index += 1
249-
if (index >= 32) advanceData(i0)
250-
i0 += 1
251-
data(index).asInstanceOf[Double]
252-
} else throwNSEE
253-
def semiclone(half: Int) = {
254-
val ans = new StepsDoubleVector(underlying, i0, half)
255-
index = 32
256-
index1 = 32
257-
i0 = half
258-
ans
259-
}
260-
}
261-
262-
private[java8] class StepsIntVector(underlying: Vector[Int], _i0: Int, _iN: Int)
263-
extends StepsIntLikeIndexed[StepsIntVector](_i0, _iN)
264-
with StepsVectorLike[Int] {
265-
protected def myVector = underlying
266-
def nextInt() = if (hasNext()) {
267-
index += 1
268-
if (index >= 32) advanceData(i0)
269-
i0 += 1
270-
data(index).asInstanceOf[Int]
271-
} else throwNSEE
272-
def semiclone(half: Int) = {
273-
val ans = new StepsIntVector(underlying, i0, half)
274-
index = 32
275-
index1 = 32
276-
i0 = half
277-
ans
278-
}
279-
}
280-
281-
private[java8] class StepsLongVector(underlying: Vector[Long], _i0: Int, _iN: Int)
282-
extends StepsLongLikeIndexed[StepsLongVector](_i0, _iN)
283-
with StepsVectorLike[Long] {
284-
protected def myVector = underlying
285-
def nextLong() = if (hasNext()) {
286-
index += 1
287-
if (index >= 32) advanceData(i0)
288-
i0 += 1
289-
data(index).asInstanceOf[Long]
290-
} else throwNSEE
291-
def semiclone(half: Int) = {
292-
val ans = new StepsLongVector(underlying, i0, half)
293-
index = 32
294-
index1 = 32
295-
i0 = half
296-
ans
297-
}
298-
}
299-
30035
private[java8] class StepsAnyFlatHashTable[A](_underlying: Array[AnyRef], _i0: Int, _iN: Int)
30136
extends StepsLikeGapped[A, StepsAnyFlatHashTable[A]](_underlying, _i0, _iN) {
30237
def next() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[A]; currentEntry = null; ans }
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package scala.compat.java8.converterImpls
2+
3+
import language.implicitConversions
4+
5+
import scala.compat.java8.collectionImpl._
6+
import scala.compat.java8.runtime._
7+
8+
import Stepper._
9+
10+
private[java8] class StepsObjectArray[A <: Object](underlying: Array[A], _i0: Int, _iN: Int)
11+
extends StepsLikeIndexed[A, StepsObjectArray[A]](_i0, _iN) {
12+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
13+
def semiclone(half: Int) = new StepsObjectArray[A](underlying, i0, half)
14+
}
15+
16+
private[java8] class StepsAnyArray[A](underlying: Array[A], _i0: Int, _iN: Int)
17+
extends StepsLikeIndexed[A, StepsAnyArray[A]](_i0, _iN) {
18+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
19+
def semiclone(half: Int) = new StepsAnyArray[A](underlying, i0, half)
20+
}
21+
22+
private[java8] class StepsUnitArray(underlying: Array[Unit], _i0: Int, _iN: Int)
23+
extends StepsLikeIndexed[Unit, StepsUnitArray](_i0, _iN) {
24+
def next() = if (hasNext()) { val j = i0; i0 += 1; () } else throwNSEE
25+
def semiclone(half: Int) = new StepsUnitArray(underlying, i0, half)
26+
}
27+
28+
private[java8] class StepsBoxedBooleanArray(underlying: Array[Boolean], _i0: Int, _iN: Int)
29+
extends StepsLikeIndexed[Boolean, StepsBoxedBooleanArray](_i0, _iN) {
30+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
31+
def semiclone(half: Int) = new StepsBoxedBooleanArray(underlying, i0, half)
32+
}
33+
34+
private[java8] class StepsBoxedByteArray(underlying: Array[Byte], _i0: Int, _iN: Int)
35+
extends StepsLikeIndexed[Byte, StepsBoxedByteArray](_i0, _iN) {
36+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
37+
def semiclone(half: Int) = new StepsBoxedByteArray(underlying, i0, half)
38+
}
39+
40+
private[java8] class StepsBoxedCharArray(underlying: Array[Char], _i0: Int, _iN: Int)
41+
extends StepsLikeIndexed[Char, StepsBoxedCharArray](_i0, _iN) {
42+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
43+
def semiclone(half: Int) = new StepsBoxedCharArray(underlying, i0, half)
44+
}
45+
46+
private[java8] class StepsBoxedShortArray(underlying: Array[Short], _i0: Int, _iN: Int)
47+
extends StepsLikeIndexed[Short, StepsBoxedShortArray](_i0, _iN) {
48+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
49+
def semiclone(half: Int) = new StepsBoxedShortArray(underlying, i0, half)
50+
}
51+
52+
private[java8] class StepsBoxedFloatArray(underlying: Array[Float], _i0: Int, _iN: Int)
53+
extends StepsLikeIndexed[Float, StepsBoxedFloatArray](_i0, _iN) {
54+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
55+
def semiclone(half: Int) = new StepsBoxedFloatArray(underlying, i0, half)
56+
}
57+
58+
private[java8] class StepsDoubleArray(underlying: Array[Double], _i0: Int, _iN: Int)
59+
extends StepsDoubleLikeIndexed[StepsDoubleArray](_i0, _iN) {
60+
def nextDouble() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
61+
def semiclone(half: Int) = new StepsDoubleArray(underlying, i0, half)
62+
}
63+
64+
private[java8] class StepsIntArray(underlying: Array[Int], _i0: Int, _iN: Int)
65+
extends StepsIntLikeIndexed[StepsIntArray](_i0, _iN) {
66+
def nextInt() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
67+
def semiclone(half: Int) = new StepsIntArray(underlying, i0, half)
68+
}
69+
70+
private[java8] class StepsLongArray(underlying: Array[Long], _i0: Int, _iN: Int)
71+
extends StepsLongLikeIndexed[StepsLongArray](_i0, _iN) {
72+
def nextLong() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
73+
def semiclone(half: Int) = new StepsLongArray(underlying, i0, half)
74+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package scala.compat.java8.converterImpls
2+
3+
import language.implicitConversions
4+
5+
import scala.compat.java8.collectionImpl._
6+
import scala.compat.java8.runtime._
7+
8+
import Stepper._
9+
10+
private[java8] class StepsAnyIndexedSeq[A](underlying: collection.IndexedSeqLike[A, _], _i0: Int, _iN: Int)
11+
extends StepsLikeIndexed[A, StepsAnyIndexedSeq[A]](_i0, _iN) {
12+
def next() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
13+
def semiclone(half: Int) = new StepsAnyIndexedSeq[A](underlying, i0, half)
14+
}
15+
16+
private[java8] class StepsDoubleIndexedSeq[CC <: collection.IndexedSeqLike[Double, _]](underlying: CC, _i0: Int, _iN: Int)
17+
extends StepsDoubleLikeIndexed[StepsDoubleIndexedSeq[CC]](_i0, _iN) {
18+
def nextDouble() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
19+
def semiclone(half: Int) = new StepsDoubleIndexedSeq[CC](underlying, i0, half)
20+
}
21+
22+
private[java8] class StepsIntIndexedSeq[CC <: collection.IndexedSeqLike[Int, _]](underlying: CC, _i0: Int, _iN: Int)
23+
extends StepsIntLikeIndexed[StepsIntIndexedSeq[CC]](_i0, _iN) {
24+
def nextInt() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
25+
def semiclone(half: Int) = new StepsIntIndexedSeq[CC](underlying, i0, half)
26+
}
27+
28+
private[java8] class StepsLongIndexedSeq[CC <: collection.IndexedSeqLike[Long, _]](underlying: CC, _i0: Int, _iN: Int)
29+
extends StepsLongLikeIndexed[StepsLongIndexedSeq[CC]](_i0, _iN) {
30+
def nextLong() = if (hasNext()) { val j = i0; i0 += 1; underlying(j) } else throwNSEE
31+
def semiclone(half: Int) = new StepsLongIndexedSeq[CC](underlying, i0, half)
32+
}

0 commit comments

Comments
 (0)