Rewrite copyInto without using copyRangeTo
Rename array copying implementation to arrayCopy
This commit is contained in:
committed by
Vasily Levchenko
parent
544fb07164
commit
356a5ac77e
@@ -538,7 +538,8 @@ public actual fun CharArray.contentToString(): String {
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun <T> Array<out T>.copyInto(destination: Array<T>, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): Array<T> {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
arrayCopy(this as Array<Any?>, startIndex, destination as Array<Any?>, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -561,7 +562,7 @@ public actual fun <T> Array<out T>.copyInto(destination: Array<T>, destinationOf
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun ByteArray.copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ByteArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -584,7 +585,7 @@ public actual fun ByteArray.copyInto(destination: ByteArray, destinationOffset:
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun ShortArray.copyInto(destination: ShortArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ShortArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -607,7 +608,7 @@ public actual fun ShortArray.copyInto(destination: ShortArray, destinationOffset
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun IntArray.copyInto(destination: IntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): IntArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -630,7 +631,7 @@ public actual fun IntArray.copyInto(destination: IntArray, destinationOffset: In
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun LongArray.copyInto(destination: LongArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): LongArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -653,7 +654,7 @@ public actual fun LongArray.copyInto(destination: LongArray, destinationOffset:
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun FloatArray.copyInto(destination: FloatArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): FloatArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -676,7 +677,7 @@ public actual fun FloatArray.copyInto(destination: FloatArray, destinationOffset
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun DoubleArray.copyInto(destination: DoubleArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): DoubleArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -699,7 +700,7 @@ public actual fun DoubleArray.copyInto(destination: DoubleArray, destinationOffs
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun BooleanArray.copyInto(destination: BooleanArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): BooleanArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -722,7 +723,7 @@ public actual fun BooleanArray.copyInto(destination: BooleanArray, destinationOf
|
||||
@SinceKotlin("1.3")
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun CharArray.copyInto(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): CharArray {
|
||||
this.copyRangeTo(destination, startIndex, endIndex, destinationOffset)
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1237,7 +1238,7 @@ public actual operator fun <T> Array<T>.plus(elements: Array<out T>): Array<T> {
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1248,7 +1249,7 @@ public actual operator fun ByteArray.plus(elements: ByteArray): ByteArray {
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1259,7 +1260,7 @@ public actual operator fun ShortArray.plus(elements: ShortArray): ShortArray {
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1270,7 +1271,7 @@ public actual operator fun IntArray.plus(elements: IntArray): IntArray {
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1281,7 +1282,7 @@ public actual operator fun LongArray.plus(elements: LongArray): LongArray {
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1292,7 +1293,7 @@ public actual operator fun FloatArray.plus(elements: FloatArray): FloatArray {
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1303,7 +1304,7 @@ public actual operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1314,7 +1315,7 @@ public actual operator fun BooleanArray.plus(elements: BooleanArray): BooleanArr
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1325,7 +1326,7 @@ public actual operator fun CharArray.plus(elements: CharArray): CharArray {
|
||||
val thisSize = size
|
||||
val arraySize = elements.size
|
||||
val result = copyOfUninitializedElements(thisSize + arraySize)
|
||||
elements.copyRangeTo(result, 0, arraySize, thisSize)
|
||||
elements.copyInto(result, thisSize)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -235,61 +235,56 @@ internal fun IntArray.fill(fromIndex: Int, toIndex: Int, value: Int) {
|
||||
|
||||
@SymbolName("Kotlin_Array_copyImpl")
|
||||
@PointsTo(0b000100, 0, 0b000001) // <array> points to <destination>, <destination> points to <array>.
|
||||
external private fun copyImpl(array: Array<Any?>, fromIndex: Int,
|
||||
internal external fun arrayCopy(array: Array<Any?>, fromIndex: Int,
|
||||
destination: Array<Any?>, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_copyImpl")
|
||||
external private fun copyImpl(array: ByteArray, fromIndex: Int,
|
||||
destination: ByteArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: ByteArray, fromIndex: Int, destination: ByteArray, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_ShortArray_copyImpl")
|
||||
external private fun copyImpl(array: ShortArray, fromIndex: Int,
|
||||
destination: ShortArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: ShortArray, fromIndex: Int, destination: ShortArray, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_CharArray_copyImpl")
|
||||
external private fun copyImpl(array: CharArray, fromIndex: Int,
|
||||
destination: CharArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: CharArray, fromIndex: Int, destination: CharArray, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_IntArray_copyImpl")
|
||||
external private fun copyImpl(array: IntArray, fromIndex: Int,
|
||||
destination: IntArray, toIndex: Int, count: Int)
|
||||
@SymbolName("Kotlin_LongArray_copyImpl")
|
||||
external private fun copyImpl(array: LongArray, fromIndex: Int,
|
||||
destination: LongArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: IntArray, fromIndex: Int, destination: IntArray, toIndex: Int, count: Int)
|
||||
|
||||
// Note: [copyImpl] for an unsigned array is bitwise identical to signed type, so
|
||||
@SymbolName("Kotlin_LongArray_copyImpl")
|
||||
internal external fun arrayCopy(array: LongArray, fromIndex: Int, destination: LongArray, toIndex: Int, count: Int)
|
||||
|
||||
// Note: [arrayCopy] for an unsigned array is bitwise identical to signed type, so
|
||||
// signed array implementations from runtime are directly reused for unsigned ones.
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_ByteArray_copyImpl")
|
||||
external private fun copyImpl(array: UByteArray, fromIndex: Int,
|
||||
destination: UByteArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: UByteArray, fromIndex: Int, destination: UByteArray, toIndex: Int, count: Int)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_ShortArray_copyImpl")
|
||||
external private fun copyImpl(array: UShortArray, fromIndex: Int,
|
||||
destination: UShortArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: UShortArray, fromIndex: Int, destination: UShortArray, toIndex: Int, count: Int)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_IntArray_copyImpl")
|
||||
external private fun copyImpl(array: UIntArray, fromIndex: Int,
|
||||
internal external fun arrayCopy(array: UIntArray, fromIndex: Int,
|
||||
destination: UIntArray, toIndex: Int, count: Int)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_LongArray_copyImpl")
|
||||
external private fun copyImpl(array: ULongArray, fromIndex: Int,
|
||||
internal external fun arrayCopy(array: ULongArray, fromIndex: Int,
|
||||
destination: ULongArray, toIndex: Int, count: Int)
|
||||
|
||||
|
||||
@SymbolName("Kotlin_FloatArray_copyImpl")
|
||||
external private fun copyImpl(array: FloatArray, fromIndex: Int,
|
||||
internal external fun arrayCopy(array: FloatArray, fromIndex: Int,
|
||||
destination: FloatArray, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_DoubleArray_copyImpl")
|
||||
external private fun copyImpl(array: DoubleArray, fromIndex: Int,
|
||||
internal external fun arrayCopy(array: DoubleArray, fromIndex: Int,
|
||||
destination: DoubleArray, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_BooleanArray_copyImpl")
|
||||
external private fun copyImpl(array: BooleanArray, fromIndex: Int,
|
||||
internal external fun arrayCopy(array: BooleanArray, fromIndex: Int,
|
||||
destination: BooleanArray, toIndex: Int, count: Int)
|
||||
|
||||
/**
|
||||
@@ -299,65 +294,65 @@ external private fun copyImpl(array: BooleanArray, fromIndex: Int,
|
||||
@PublishedApi
|
||||
internal fun <E> Array<out E>.copyRangeTo(
|
||||
destination: Array<in E>, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(@Suppress("UNCHECKED_CAST") (this as Array<Any?>), fromIndex,
|
||||
arrayCopy(@Suppress("UNCHECKED_CAST") (this as Array<Any?>), fromIndex,
|
||||
@Suppress("UNCHECKED_CAST") (destination as Array<Any?>),
|
||||
destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun ByteArray.copyRangeTo(destination: ByteArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun ShortArray.copyRangeTo(destination: ShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun CharArray.copyRangeTo(destination: CharArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun IntArray.copyRangeTo(destination: IntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun LongArray.copyRangeTo(destination: LongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun UByteArray.copyRangeTo(destination: UByteArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun UShortArray.copyRangeTo(destination: UShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun UIntArray.copyRangeTo(destination: UIntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun ULongArray.copyRangeTo(destination: ULongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun FloatArray.copyRangeTo(destination: FloatArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun DoubleArray.copyRangeTo(destination: DoubleArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun BooleanArray.copyRangeTo(destination: BooleanArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun <E> Collection<E>.collectionToString(): String {
|
||||
|
||||
Reference in New Issue
Block a user