@@ -6,61 +6,14 @@ object DynamicTuple {
6
6
inline val MaxSpecialized = 22
7
7
inline private val XXL = MaxSpecialized + 1
8
8
9
- def to$Array (it : Iterator [Any ], n : Int , arr : Array [Object ], offset : Int ): Unit = {
9
+ def itToArray (it : Iterator [Any ], size : Int , dest : Array [Object ], offset : Int ): Unit = {
10
10
var i = 0
11
- while (i < n ) {
12
- arr (offset + i) = it.next().asInstanceOf [Object ]
11
+ while (i < size ) {
12
+ dest (offset + i) = it.next().asInstanceOf [Object ]
13
13
i += 1
14
14
}
15
15
}
16
16
17
- def cons$Array [H ](x : H , elems : Array [Object ]): Array [Object ] = {
18
- val elems1 = new Array [Object ](elems.length + 1 )
19
- elems1(0 ) = x.asInstanceOf [Object ]
20
- System .arraycopy(elems, 0 , elems1, 1 , elems.length)
21
- elems1
22
- }
23
-
24
- def concat$Array (a1 : Array [Object ], a2 : Array [Object ]): Array [Object ] = {
25
- val result = new Array [Object ](a1.length + a2.length)
26
- System .arraycopy(a1, 0 , result, 0 , a1.length)
27
- System .arraycopy(a2, 0 , result, a1.length, a2.length)
28
- result
29
- }
30
-
31
- def dynamicFromIterator [T <: Tuple ](it : Iterator [Object ], size : Int ): T = size match {
32
- case 1 => Tuple1 (it.next()).asInstanceOf [T ]
33
- case 2 => Tuple2 (it.next(), it.next()).asInstanceOf [T ]
34
- case 3 => Tuple3 (it.next(), it.next(), it.next()).asInstanceOf [T ]
35
- case 4 => Tuple4 (it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
36
- case 5 => Tuple5 (it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
37
- case 6 => Tuple6 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
38
- case 7 => Tuple7 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
39
- case 8 => Tuple8 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
40
- case 9 => Tuple9 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
41
- case 10 => Tuple10 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
42
- case 11 => Tuple11 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
43
- case 12 => Tuple12 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
44
- case 13 => Tuple13 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
45
- case 14 => Tuple14 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
46
- case 15 => Tuple15 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
47
- case 16 => Tuple16 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
48
- case 17 => Tuple17 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
49
- case 18 => Tuple18 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
50
- case 19 => Tuple19 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
51
- case 20 => Tuple20 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
52
- case 21 => Tuple21 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
53
- case 22 => Tuple22 (it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next(), it.next()).asInstanceOf [T ]
54
- case _ =>
55
- val arr : Array [Object ] = new Array [Object ](size)
56
- var i = 0
57
- while (i < size) {
58
- arr(i) = it.next()
59
- i += 1
60
- }
61
- TupleXXL .fromIArray(arr.asInstanceOf [IArray [Object ]]).asInstanceOf [T ]
62
- }
63
-
64
17
def dynamicFromArray [T <: Tuple ](xs : Array [Object ]): T = xs.length match {
65
18
case 0 => ().asInstanceOf [T ]
66
19
case 1 => Tuple1 (xs(0 )).asInstanceOf [T ]
@@ -280,8 +233,16 @@ object DynamicTuple {
280
233
Tuple21 (x, self._1, self._2, self._3, self._4, self._5, self._6, self._7, self._8, self._9, self._10, self._11, self._12, self._13, self._14, self._15, self._16, self._17, self._18, self._19, self._20)
281
234
case self : Tuple21 [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] =>
282
235
Tuple22 (x, self._1, self._2, self._3, self._4, self._5, self._6, self._7, self._8, self._9, self._10, self._11, self._12, self._13, self._14, self._15, self._16, self._17, self._18, self._19, self._20, self._21)
283
- case _ =>
284
- dynamicFromIterator[Result ](consIterator(x, self).asInstanceOf [Iterator [Object ]], self.size + 1 )
236
+ case self : Tuple22 [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] =>
237
+ val arr = new Array [Object ](23 )
238
+ itToArray(self.asInstanceOf [Product ].productIterator, 22 , arr, 1 )
239
+ arr(0 ) = x.asInstanceOf [Object ]
240
+ dynamicFromIArray[Result ](arr.asInstanceOf [IArray [Object ]])
241
+ case xxl : TupleXXL =>
242
+ val arr = new Array [Object ](self.size + 1 )
243
+ System .arraycopy(xxl.elems, 0 , arr, 1 , self.size)
244
+ arr(0 ) = x.asInstanceOf [Object ]
245
+ dynamicFromIArray[Result ](arr.asInstanceOf [IArray [Object ]])
285
246
}
286
247
res.asInstanceOf [Result ]
287
248
}
@@ -296,7 +257,22 @@ object DynamicTuple {
296
257
case that : Unit => return self.asInstanceOf [Result ]
297
258
case _ =>
298
259
}
299
- dynamicFromIterator[Result ](concatIterator(self, that).asInstanceOf [Iterator [Object ]], self.size + that.size)
260
+
261
+ val arr = new Array [Object ](self.size + that.size)
262
+
263
+ if (self.size <= 22 ) {
264
+ itToArray(self.asInstanceOf [Product ].productIterator, self.size, arr, 0 )
265
+ } else {
266
+ System .arraycopy(self.asInstanceOf [TupleXXL ].elems, 0 , arr, 0 , self.size)
267
+ }
268
+
269
+ if (that.size <= 22 ) {
270
+ itToArray(that.asInstanceOf [Product ].productIterator, that.size, arr, 0 )
271
+ } else {
272
+ System .arraycopy(that.asInstanceOf [TupleXXL ].elems, 0 , arr, self.size, that.size)
273
+ }
274
+
275
+ dynamicFromIArray[Result ](arr.asInstanceOf [IArray [Object ]]).asInstanceOf [Result ]
300
276
}
301
277
302
278
def dynamicSize [This <: Tuple ](self : This ): Size [This ] = (self : Any ) match {
@@ -351,10 +327,10 @@ object DynamicTuple {
351
327
Tuple20 (self._2, self._3, self._4, self._5, self._6, self._7, self._8, self._9, self._10, self._11, self._12, self._13, self._14, self._15, self._16, self._17, self._18, self._19, self._20, self._21)
352
328
case self : Tuple22 [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] =>
353
329
Tuple21 (self._2, self._3, self._4, self._5, self._6, self._7, self._8, self._9, self._10, self._11, self._12, self._13, self._14, self._15, self._16, self._17, self._18, self._19, self._20, self._21, self._22)
354
- case _ =>
355
- val it = self. asInstanceOf [ Product ].productIterator. asInstanceOf [ Iterator [ Object ]]
356
- it.next( )
357
- dynamicFromIterator(it, self.size - 1 )
330
+ case xxl : TupleXXL =>
331
+ val arr = new Array [ Object ](self.size - 1 )
332
+ System .arraycopy(xxl.elems, 1 , arr, 0 , self.size - 1 )
333
+ dynamicFromIArray[ Result ](arr. asInstanceOf [ IArray [ Object ]] )
358
334
}
359
335
res.asInstanceOf [Result ]
360
336
}
0 commit comments