[WASM] Add array copy intrinsic
This commit is contained in:
@@ -1017,18 +1017,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> {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
arrayCopy(this as Array<Any?>, startIndex, destination as Array<Any?>, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1051,18 +1041,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1085,18 +1064,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1119,18 +1087,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1153,18 +1110,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1187,18 +1133,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1221,18 +1156,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1255,18 +1179,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
@@ -1289,18 +1202,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 {
|
||||
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
|
||||
val rangeSize = endIndex - startIndex
|
||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||
if (this !== destination || destinationOffset <= startIndex) {
|
||||
for (index in 0 until rangeSize) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
} else {
|
||||
for (index in rangeSize - 1 downTo 0) {
|
||||
destination[destinationOffset + index] = this[startIndex + index]
|
||||
}
|
||||
}
|
||||
arrayCopy(this, startIndex, destination, destinationOffset, endIndex - startIndex)
|
||||
return destination
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,11 @@ internal class WasmAnyArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmAnyArray.copyTo(destination: WasmAnyArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmAnyArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmAnyArray.fill(size: Int, init: (Int) -> Any?) {
|
||||
@@ -41,8 +45,7 @@ internal inline fun WasmAnyArray.fill(size: Int, init: (Int) -> Any?) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@WasmArrayOf(Byte::class, isNullable = false)
|
||||
internal class WasmByteArray(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET_S)
|
||||
@@ -55,7 +58,11 @@ internal class WasmByteArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmByteArray.copyTo(destination: WasmByteArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmByteArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmByteArray.fill(size: Int, init: (Int) -> Byte) {
|
||||
@@ -64,8 +71,7 @@ internal inline fun WasmByteArray.fill(size: Int, init: (Int) -> Byte) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@WasmArrayOf(Char::class, isNullable = false)
|
||||
internal class WasmCharArray(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET_U)
|
||||
@@ -78,7 +84,11 @@ internal class WasmCharArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmCharArray.copyTo(destination: WasmCharArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmCharArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmCharArray.fill(size: Int, init: (Int) -> Char) {
|
||||
@@ -87,8 +97,7 @@ internal inline fun WasmCharArray.fill(size: Int, init: (Int) -> Char) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@WasmArrayOf(Short::class, isNullable = false)
|
||||
internal class WasmShortArray(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET_S)
|
||||
@@ -101,7 +110,11 @@ internal class WasmShortArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmShortArray.copyTo(destination: WasmShortArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmShortArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmShortArray.fill(size: Int, init: (Int) -> Short) {
|
||||
@@ -110,8 +123,7 @@ internal inline fun WasmShortArray.fill(size: Int, init: (Int) -> Short) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@WasmArrayOf(Int::class, isNullable = false)
|
||||
internal class WasmIntArray(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET)
|
||||
@@ -124,7 +136,11 @@ internal class WasmIntArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmIntArray.copyTo(destination: WasmIntArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmIntArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmIntArray.fill(size: Int, init: (Int) -> Int) {
|
||||
@@ -133,8 +149,7 @@ internal inline fun WasmIntArray.fill(size: Int, init: (Int) -> Int) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@WasmArrayOf(Long::class, isNullable = false)
|
||||
internal class WasmLongArray(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET)
|
||||
@@ -147,7 +162,11 @@ internal class WasmLongArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmLongArray.copyTo(destination: WasmLongArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmLongArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmLongArray.fill(size: Int, init: (Int) -> Long) {
|
||||
@@ -156,8 +175,7 @@ internal inline fun WasmLongArray.fill(size: Int, init: (Int) -> Long) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@WasmArrayOf(Float::class, isNullable = false)
|
||||
internal class WasmFloatArray(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET)
|
||||
@@ -170,7 +188,11 @@ internal class WasmFloatArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmFloatArray.copyTo(destination: WasmFloatArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmFloatArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmFloatArray.fill(size: Int, init: (Int) -> Float) {
|
||||
@@ -179,8 +201,7 @@ internal inline fun WasmFloatArray.fill(size: Int, init: (Int) -> Float) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@WasmArrayOf(Double::class, isNullable = false)
|
||||
internal class WasmDoubleArray(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET)
|
||||
@@ -193,7 +214,11 @@ internal class WasmDoubleArray(size: Int) {
|
||||
|
||||
@WasmOp(WasmOp.ARRAY_LEN)
|
||||
fun len(): Int =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
internal inline fun WasmDoubleArray.copyTo(destination: WasmDoubleArray, sourceIndex: Int, destinationIndex: Int, length: Int) {
|
||||
wasm_array_copy<WasmDoubleArray>(destination, destinationIndex, this, sourceIndex, length)
|
||||
}
|
||||
|
||||
internal inline fun WasmDoubleArray.fill(size: Int, init: (Int) -> Double) {
|
||||
@@ -202,5 +227,4 @@ internal inline fun WasmDoubleArray.fill(size: Int, init: (Int) -> Double) {
|
||||
set(i, init(i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -252,6 +252,7 @@ internal annotation class WasmOp(val name: String) {
|
||||
const val ARRAY_GET_U = "ARRAY_GET_U"
|
||||
const val ARRAY_SET = "ARRAY_SET"
|
||||
const val ARRAY_LEN = "ARRAY_LEN"
|
||||
const val ARRAY_COPY = "ARRAY_COPY"
|
||||
const val I31_NEW = "I31_NEW"
|
||||
const val I31_GET_S = "I31_GET_S"
|
||||
const val I31_GET_U = "I31_GET_U"
|
||||
|
||||
Reference in New Issue
Block a user