copyInto: copying elements between two arrays
#KT-25874 Fixed
This commit is contained in:
@@ -407,6 +407,222 @@ public actual fun CharArray.contentToString(): String {
|
||||
definedExternally
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun <T> Array<out T>.copyInto(destination: Array<T>, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): Array<T> {
|
||||
arrayCopy(this, destination, destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun ByteArray.copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ByteArray {
|
||||
arrayCopy(this.unsafeCast<Array<Byte>>(), destination.unsafeCast<Array<Byte>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun ShortArray.copyInto(destination: ShortArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ShortArray {
|
||||
arrayCopy(this.unsafeCast<Array<Short>>(), destination.unsafeCast<Array<Short>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun IntArray.copyInto(destination: IntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): IntArray {
|
||||
arrayCopy(this.unsafeCast<Array<Int>>(), destination.unsafeCast<Array<Int>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun LongArray.copyInto(destination: LongArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): LongArray {
|
||||
arrayCopy(this.unsafeCast<Array<Long>>(), destination.unsafeCast<Array<Long>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun FloatArray.copyInto(destination: FloatArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): FloatArray {
|
||||
arrayCopy(this.unsafeCast<Array<Float>>(), destination.unsafeCast<Array<Float>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun DoubleArray.copyInto(destination: DoubleArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): DoubleArray {
|
||||
arrayCopy(this.unsafeCast<Array<Double>>(), destination.unsafeCast<Array<Double>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun BooleanArray.copyInto(destination: BooleanArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): BooleanArray {
|
||||
arrayCopy(this.unsafeCast<Array<Boolean>>(), destination.unsafeCast<Array<Boolean>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this array or its subrange into the [destination] array and returns that array.
|
||||
*
|
||||
* It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range.
|
||||
*
|
||||
* @param destination the array to copy to.
|
||||
* @param destinationOffset the position in the [destination] array to copy to, 0 by default.
|
||||
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||
* @param endIndex the end (exclusive) of the subrange to copy, size of this array by default.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`.
|
||||
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationIndex],
|
||||
* or when that index is out of the [destination] array indices range.
|
||||
*
|
||||
* @return the [destination] array.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual inline fun CharArray.copyInto(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): CharArray {
|
||||
arrayCopy(this.unsafeCast<Array<Char>>(), destination.unsafeCast<Array<Char>>(), destinationOffset, startIndex, endIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user