From 0c81e30d46067914bbaabb3a27e097375e819ac9 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 26 Sep 2018 05:01:57 +0300 Subject: [PATCH] Make a more correct implementation of unsigned arrays copyInto Return the destination array instead of the destination storage array wrapped in a new unsigned array. The difference should be indistinguishable, however in JS, where inline classes are not inlined yet, it had resulted in an extra wrapper. --- libraries/stdlib/common/src/generated/_UArrays.kt | 12 ++++++++---- .../tools/kotlin-stdlib-gen/src/templates/Arrays.kt | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index 4236c3e2b24..d601b7cfc50 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -346,7 +346,8 @@ public fun UShortArray.contentToString(): String { @ExperimentalUnsignedTypes @kotlin.internal.InlineOnly public inline fun UIntArray.copyInto(destination: UIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): UIntArray { - return UIntArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex)) + storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex) + return destination } /** @@ -369,7 +370,8 @@ public inline fun UIntArray.copyInto(destination: UIntArray, destinationOffset: @ExperimentalUnsignedTypes @kotlin.internal.InlineOnly public inline fun ULongArray.copyInto(destination: ULongArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ULongArray { - return ULongArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex)) + storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex) + return destination } /** @@ -392,7 +394,8 @@ public inline fun ULongArray.copyInto(destination: ULongArray, destinationOffset @ExperimentalUnsignedTypes @kotlin.internal.InlineOnly public inline fun UByteArray.copyInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): UByteArray { - return UByteArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex)) + storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex) + return destination } /** @@ -415,7 +418,8 @@ public inline fun UByteArray.copyInto(destination: UByteArray, destinationOffset @ExperimentalUnsignedTypes @kotlin.internal.InlineOnly public inline fun UShortArray.copyInto(destination: UShortArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): UShortArray { - return UShortArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex)) + storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex) + return destination } /** diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt index 51b7319a327..2334f710d3c 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt @@ -517,7 +517,10 @@ object ArrayOps : TemplateGroupBase() { specialFor(ArraysOfUnsigned) { inlineOnly() body { - "return SELF(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex))" + """ + storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex) + return destination + """ } } specialFor(ArraysOfPrimitives, InvariantArraysOfObjects) {