Optimize copying for typed arrays in JS
This commit is contained in:
@@ -136,13 +136,18 @@ internal fun <T> arrayCopy(source: Array<out T>, destination: Array<in T>, desti
|
|||||||
val rangeSize = endIndex - startIndex
|
val rangeSize = endIndex - startIndex
|
||||||
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
|
||||||
|
|
||||||
if (source !== destination || destinationOffset <= startIndex) {
|
if (js("ArrayBuffer").isView(destination) && js("ArrayBuffer").isView(source)) {
|
||||||
for (index in 0 until rangeSize) {
|
val subrange = source.asDynamic().subarray(startIndex, endIndex)
|
||||||
destination[destinationOffset + index] = source[startIndex + index]
|
destination.asDynamic().set(subrange, destinationOffset)
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (index in rangeSize - 1 downTo 0) {
|
if (source !== destination || destinationOffset <= startIndex) {
|
||||||
destination[destinationOffset + index] = source[startIndex + index]
|
for (index in 0 until rangeSize) {
|
||||||
|
destination[destinationOffset + index] = source[startIndex + index]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (index in rangeSize - 1 downTo 0) {
|
||||||
|
destination[destinationOffset + index] = source[startIndex + index]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user