Skip to content

Commit 6ee2edb

Browse files
author
Antoine Brunner
committed
Factorize code in tuple concat
1 parent 4d47151 commit 6ee2edb

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

library/src/scala/runtime/DynamicTuple.scala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ object DynamicTuple {
263263

264264
def dynamicConcat[This <: Tuple, That <: Tuple](self: This, that: That): Concat[This, That] = {
265265
type Result = Concat[This, That]
266+
266267
(self: Any) match {
267268
case self: Unit => return that.asInstanceOf[Result]
268269
case _ =>
@@ -275,20 +276,15 @@ object DynamicTuple {
275276

276277
val arr = new Array[Object](self.size + that.size)
277278

278-
(self: Any) match {
279-
case xxl: TupleXXL =>
280-
System.arraycopy(xxl.elems, 0, arr, 0, self.size)
281-
case _ =>
282-
itToArray(self.asInstanceOf[Product].productIterator, self.size, arr, 0)
283-
}
284-
285-
(that: Any) match {
279+
inline def copyToArray[T <: Tuple](tuple: T, array: Array[Object], offset: Int): Unit = (tuple: Any) match {
286280
case xxl: TupleXXL =>
287-
System.arraycopy(xxl.elems, 0, arr, self.size, that.size)
281+
System.arraycopy(xxl.elems, 0, array, offset, tuple.size)
288282
case _ =>
289-
itToArray(that.asInstanceOf[Product].productIterator, that.size, arr, self.size)
283+
itToArray(tuple.asInstanceOf[Product].productIterator, tuple.size, array, offset)
290284
}
291285

286+
copyToArray(self, arr, 0)
287+
copyToArray(that, arr, self.size)
292288
dynamicFromIArray[Result](arr.asInstanceOf[IArray[Object]])
293289
}
294290

0 commit comments

Comments
 (0)