From 22aad2d17c670ec0fb76d5781c59037b81228fce Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Thu, 27 Sep 2018 18:49:00 +0300 Subject: [PATCH] Fix Array.copyInto to remove workaround on endIndex with default value from expect (#2148) --- .../main/kotlin/kotlin/collections/Arrays.kt | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt index 613ec1b5c2f..54d1a119f09 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt @@ -622,8 +622,7 @@ public inline fun Array.subarrayContentToString(offset: Int, length: */ @SinceKotlin("1.3") public actual fun Array.copyInto(destination: Array, destinationOffset: Int, startIndex: Int, endIndex: Int): Array { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -645,8 +644,7 @@ public actual fun Array.copyInto(destination: Array, destinationOf */ @SinceKotlin("1.3") public actual fun ByteArray.copyInto(destination: ByteArray, destinationOffset: Int, startIndex: Int, endIndex: Int): ByteArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -668,8 +666,7 @@ public actual fun ByteArray.copyInto(destination: ByteArray, destinationOffset: */ @SinceKotlin("1.3") public actual fun ShortArray.copyInto(destination: ShortArray, destinationOffset: Int, startIndex: Int, endIndex: Int): ShortArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -691,8 +688,7 @@ public actual fun ShortArray.copyInto(destination: ShortArray, destinationOffset */ @SinceKotlin("1.3") public actual fun IntArray.copyInto(destination: IntArray, destinationOffset: Int, startIndex: Int, endIndex: Int): IntArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -714,8 +710,7 @@ public actual fun IntArray.copyInto(destination: IntArray, destinationOffset: In */ @SinceKotlin("1.3") public actual fun LongArray.copyInto(destination: LongArray, destinationOffset: Int, startIndex: Int, endIndex: Int): LongArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -737,8 +732,7 @@ public actual fun LongArray.copyInto(destination: LongArray, destinationOffset: */ @SinceKotlin("1.3") public actual fun FloatArray.copyInto(destination: FloatArray, destinationOffset: Int, startIndex: Int, endIndex: Int): FloatArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -760,8 +754,7 @@ public actual fun FloatArray.copyInto(destination: FloatArray, destinationOffset */ @SinceKotlin("1.3") public actual fun DoubleArray.copyInto(destination: DoubleArray, destinationOffset: Int, startIndex: Int, endIndex: Int): DoubleArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -783,8 +776,7 @@ public actual fun DoubleArray.copyInto(destination: DoubleArray, destinationOffs */ @SinceKotlin("1.3") public actual fun BooleanArray.copyInto(destination: BooleanArray, destinationOffset: Int, startIndex: Int, endIndex: Int): BooleanArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination } @@ -806,8 +798,7 @@ public actual fun BooleanArray.copyInto(destination: BooleanArray, destinationOf */ @SinceKotlin("1.3") public actual fun CharArray.copyInto(destination: CharArray, destinationOffset: Int, startIndex: Int, endIndex: Int): CharArray { - val realEndIndex = if (endIndex == -1) this.size else endIndex // TODO: Remove when default value from expect is fixed - this.copyRangeTo(destination, startIndex, realEndIndex, destinationOffset) + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) return destination }