Replace remaining usages of copyRangeTo to copyInto and drop copyRangeTo
This commit is contained in:
committed by
Vasily Levchenko
parent
cfa7c12413
commit
cfefbc184b
@@ -200,7 +200,7 @@ actual class ArrayList<E> private constructor(
|
||||
|
||||
private fun insertAtInternal(i: Int, n: Int) {
|
||||
ensureExtraCapacity(n)
|
||||
array.copyRangeTo(array, fromIndex = i, toIndex = offset + length, destinationIndex = i + n)
|
||||
array.copyInto(array, startIndex = i, endIndex = offset + length, destinationOffset = i + n)
|
||||
length += n
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ actual class ArrayList<E> private constructor(
|
||||
return old
|
||||
} else {
|
||||
val old = array[i]
|
||||
array.copyRangeTo(array, fromIndex = i + 1, toIndex = offset + length, destinationIndex = i)
|
||||
array.copyInto(array, startIndex = i + 1, endIndex = offset + length, destinationOffset = i)
|
||||
array.resetAt(offset + length - 1)
|
||||
length--
|
||||
return old
|
||||
@@ -249,7 +249,7 @@ actual class ArrayList<E> private constructor(
|
||||
if (backing != null) {
|
||||
backing.removeRangeInternal(rangeOffset, rangeLength)
|
||||
} else {
|
||||
array.copyRangeTo(array, fromIndex = rangeOffset + rangeLength, toIndex = length, destinationIndex = rangeOffset)
|
||||
array.copyInto(array, startIndex = rangeOffset + rangeLength, endIndex = length, destinationOffset = rangeOffset)
|
||||
array.resetRange(fromIndex = length - rangeLength, toIndex = length)
|
||||
}
|
||||
length -= rangeLength
|
||||
@@ -272,7 +272,7 @@ actual class ArrayList<E> private constructor(
|
||||
}
|
||||
}
|
||||
val removed = rangeLength - j
|
||||
array.copyRangeTo(array, fromIndex = rangeOffset + rangeLength, toIndex = length, destinationIndex = rangeOffset + j)
|
||||
array.copyInto(array, startIndex = rangeOffset + rangeLength, endIndex = length, destinationOffset = rangeOffset + j)
|
||||
array.resetRange(fromIndex = length - removed, toIndex = length)
|
||||
length -= removed
|
||||
return removed
|
||||
|
||||
@@ -99,8 +99,7 @@ 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>.
|
||||
internal external fun arrayCopy(array: Array<Any?>, fromIndex: Int,
|
||||
destination: Array<Any?>, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: Array<Any?>, fromIndex: Int, destination: Array<Any?>, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_copyImpl")
|
||||
internal external fun arrayCopy(array: ByteArray, fromIndex: Int, destination: ByteArray, toIndex: Int, count: Int)
|
||||
@@ -117,107 +116,15 @@ internal external fun arrayCopy(array: IntArray, fromIndex: Int, destination: In
|
||||
@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")
|
||||
internal external fun arrayCopy(array: UByteArray, fromIndex: Int, destination: UByteArray, toIndex: Int, count: Int)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_ShortArray_copyImpl")
|
||||
internal external fun arrayCopy(array: UShortArray, fromIndex: Int, destination: UShortArray, toIndex: Int, count: Int)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_IntArray_copyImpl")
|
||||
internal external fun arrayCopy(array: UIntArray, fromIndex: Int,
|
||||
destination: UIntArray, toIndex: Int, count: Int)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_LongArray_copyImpl")
|
||||
internal external fun arrayCopy(array: ULongArray, fromIndex: Int,
|
||||
destination: ULongArray, toIndex: Int, count: Int)
|
||||
|
||||
|
||||
@SymbolName("Kotlin_FloatArray_copyImpl")
|
||||
internal external fun arrayCopy(array: FloatArray, fromIndex: Int,
|
||||
destination: FloatArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: FloatArray, fromIndex: Int, destination: FloatArray, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_DoubleArray_copyImpl")
|
||||
internal external fun arrayCopy(array: DoubleArray, fromIndex: Int,
|
||||
destination: DoubleArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: DoubleArray, fromIndex: Int, destination: DoubleArray, toIndex: Int, count: Int)
|
||||
|
||||
@SymbolName("Kotlin_BooleanArray_copyImpl")
|
||||
internal external fun arrayCopy(array: BooleanArray, fromIndex: Int,
|
||||
destination: BooleanArray, toIndex: Int, count: Int)
|
||||
internal external fun arrayCopy(array: BooleanArray, fromIndex: Int, destination: BooleanArray, toIndex: Int, count: Int)
|
||||
|
||||
/**
|
||||
* Copies a range of array elements at a specified [fromIndex] (inclusive) to [toIndex] (exclusive) range of indices
|
||||
* to another [destination] array starting at [destinationIndex].
|
||||
*/
|
||||
@PublishedApi
|
||||
internal fun <E> Array<out E>.copyRangeTo(
|
||||
destination: Array<in E>, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
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) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun ShortArray.copyRangeTo(destination: ShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun CharArray.copyRangeTo(destination: CharArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun IntArray.copyRangeTo(destination: IntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun LongArray.copyRangeTo(destination: LongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun UByteArray.copyRangeTo(destination: UByteArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun UShortArray.copyRangeTo(destination: UShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun UIntArray.copyRangeTo(destination: UIntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun ULongArray.copyRangeTo(destination: ULongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun FloatArray.copyRangeTo(destination: FloatArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun DoubleArray.copyRangeTo(destination: DoubleArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun BooleanArray.copyRangeTo(destination: BooleanArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
arrayCopy(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
internal fun <E> Collection<E>.collectionToString(): String {
|
||||
val sb = StringBuilder(2 + size * 3)
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MutableData constructor(capacity: Int = 16) {
|
||||
if (newSize > buffer.size) {
|
||||
val actualSize = maxOf(buffer.size * 3 / 2 + 1, newSize)
|
||||
val newBuffer = ByteArray(actualSize)
|
||||
buffer.copyRangeTo(newBuffer, 0, size, 0)
|
||||
buffer.copyInto(newBuffer, startIndex = 0, endIndex = size)
|
||||
newBuffer.share()
|
||||
buffer = newBuffer
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class MutableData constructor(capacity: Int = 16) {
|
||||
throw IndexOutOfBoundsException("$fromIndex is bigger than $toIndex")
|
||||
if (toIndex == toIndex) return
|
||||
val where = resizeDataLocked(this.size + (toIndex - fromIndex))
|
||||
data.copyRangeTo(buffer, fromIndex, toIndex, where)
|
||||
data.copyInto(buffer, where, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ public class MutableData constructor(capacity: Int = 16) {
|
||||
* Copies range of mutable data to the byte array.
|
||||
*/
|
||||
public fun copyInto(output: ByteArray, destinationIndex: Int, startIndex: Int, endIndex: Int): Unit = locked(lock) {
|
||||
buffer.copyRangeTo(output, startIndex, endIndex, destinationIndex)
|
||||
buffer.copyInto(output, destinationIndex, startIndex, endIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -168,7 +168,7 @@ actual class StringBuilder private constructor (
|
||||
val extraLength = end - start
|
||||
ensureExtraCapacity(extraLength)
|
||||
|
||||
array.copyRangeTo(array, index, _length, index + extraLength)
|
||||
array.copyInto(array, startIndex = index, endIndex = _length, destinationOffset = index + extraLength)
|
||||
var from = start
|
||||
var to = index
|
||||
while (from < end) {
|
||||
@@ -183,8 +183,8 @@ actual class StringBuilder private constructor (
|
||||
checkInsertIndex(index)
|
||||
ensureExtraCapacity(chars.size)
|
||||
|
||||
array.copyRangeTo(array, index, _length, index + chars.size)
|
||||
chars.copyRangeTo(array, 0, chars.size, index)
|
||||
array.copyInto(array, startIndex = index, endIndex = _length, destinationOffset = index + chars.size)
|
||||
chars.copyInto(array, destinationOffset = index)
|
||||
|
||||
_length += chars.size
|
||||
return this
|
||||
@@ -193,7 +193,7 @@ actual class StringBuilder private constructor (
|
||||
fun insert(index: Int, string: String): StringBuilder {
|
||||
checkInsertIndex(index)
|
||||
ensureExtraCapacity(string.length)
|
||||
array.copyRangeTo(array, index, _length, index + string.length)
|
||||
array.copyInto(array, startIndex = index, endIndex = _length, destinationOffset = index + string.length)
|
||||
_length += insertString(array, index, string)
|
||||
return this
|
||||
}
|
||||
@@ -235,7 +235,7 @@ actual class StringBuilder private constructor (
|
||||
|
||||
fun append(it: CharArray): StringBuilder {
|
||||
ensureExtraCapacity(it.size)
|
||||
it.copyRangeTo(array, 0, it.size, _length)
|
||||
it.copyInto(array, _length)
|
||||
_length += it.size
|
||||
return this
|
||||
}
|
||||
@@ -262,7 +262,7 @@ actual class StringBuilder private constructor (
|
||||
|
||||
fun deleteCharAt(index: Int) {
|
||||
checkIndex(index)
|
||||
array.copyRangeTo(array, index + 1, _length, index)
|
||||
array.copyInto(array, startIndex = index + 1, endIndex = _length, destinationOffset = index)
|
||||
--_length
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user