@@ -274,31 +274,29 @@ object DynamicTuple {
274274 def dynamicConcat [This <: Tuple , That <: Tuple ](self : This , that : That ): Concat [This , That ] = {
275275 type Result = Concat [This , That ]
276276
277+ val selfSize : Int = self.size
277278 // If one of the tuples is empty, we can leave early
278- (self : Any ) match {
279- case self : Unit => return that.asInstanceOf [Result ]
280- case _ =>
281- }
279+ if selfSize == 0 then
280+ return that.asInstanceOf [Result ]
282281
283- (that : Any ) match {
284- case that : Unit => return self.asInstanceOf [Result ]
285- case _ =>
286- }
282+ val thatSize : Int = that.size
283+ if thatSize == 0 then
284+ return self.asInstanceOf [Result ]
287285
288- val arr = new Array [Object ](self.size + that.size )
286+ val arr = new Array [Object ](selfSize + thatSize )
289287
290288 // Copies the tuple to an array, at the given offset
291- inline def copyToArray [T <: Tuple ](tuple : T , array : Array [Object ], offset : Int ): Unit = (tuple : Any ) match {
289+ inline def copyToArray [T <: Tuple ](tuple : T , size : Int , array : Array [Object ], offset : Int ): Unit = (tuple : Any ) match {
292290 case xxl : TupleXXL =>
293- System .arraycopy(xxl.elems, 0 , array, offset, tuple. size)
291+ System .arraycopy(xxl.elems, 0 , array, offset, size)
294292 case _ =>
295293 tuple.asInstanceOf [Product ].productIterator.asInstanceOf [Iterator [Object ]]
296- .copyToArray(array, offset, tuple. size)
294+ .copyToArray(array, offset, size)
297295 }
298296
299297 // In the general case, we copy the two tuples to an array, and convert it back to a tuple
300- copyToArray(self, arr, 0 )
301- copyToArray(that, arr, self.size )
298+ copyToArray(self, selfSize, arr, 0 )
299+ copyToArray(that, thatSize, arr, selfSize )
302300 dynamicFromIArray[Result ](arr.asInstanceOf [IArray [Object ]])
303301 }
304302
@@ -401,9 +399,11 @@ object DynamicTuple {
401399 }
402400
403401 def dynamicZip [This <: Tuple , T2 <: Tuple ](t1 : This , t2 : T2 ): Zip [This , T2 ] = {
404- if (t1.size == 0 || t2.size == 0 ) return ().asInstanceOf [Zip [This , T2 ]]
405- val size = Math .min(t1.size, t2.size)
406- Tuple .fromIArray(
402+ val t1Size : Int = t1.size
403+ val t2Size : Int = t2.size
404+ val size = Math .min(t1Size, t2Size)
405+ if size == 0 then ().asInstanceOf [Zip [This , T2 ]]
406+ else Tuple .fromIArray(
407407 zipIterators(
408408 t1.asInstanceOf [Product ].productIterator,
409409 t2.asInstanceOf [Product ].productIterator,
@@ -475,7 +475,8 @@ object DynamicTuple {
475475
476476 def dynamicTake [This <: Tuple , N <: Int ](self : This , n : N ): Take [This , N ] = {
477477 if (n < 0 ) throw new IndexOutOfBoundsException (n.toString)
478- val actualN = Math .min(n, self.size)
478+ val selfSize : Int = self.size
479+ val actualN = Math .min(n, selfSize)
479480
480481 type Result = Take [This , N ]
481482
0 commit comments