Remove Array.copyRange and replace its internal usages with copyRangeTo
This commit is contained in:
committed by
Pavel Punegov
parent
366bb0c5e6
commit
653c740330
@@ -200,7 +200,7 @@ actual class ArrayList<E> private constructor(
|
|||||||
|
|
||||||
private fun insertAtInternal(i: Int, n: Int) {
|
private fun insertAtInternal(i: Int, n: Int) {
|
||||||
ensureExtraCapacity(n)
|
ensureExtraCapacity(n)
|
||||||
array.copyRange(fromIndex = i, toIndex = offset + length, destinationIndex = i + n)
|
array.copyRangeTo(array, fromIndex = i, toIndex = offset + length, destinationIndex = i + n)
|
||||||
length += n
|
length += n
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ actual class ArrayList<E> private constructor(
|
|||||||
return old
|
return old
|
||||||
} else {
|
} else {
|
||||||
val old = array[i]
|
val old = array[i]
|
||||||
array.copyRange(fromIndex = i + 1, toIndex = offset + length, destinationIndex = i)
|
array.copyRangeTo(array, fromIndex = i + 1, toIndex = offset + length, destinationIndex = i)
|
||||||
array.resetAt(offset + length - 1)
|
array.resetAt(offset + length - 1)
|
||||||
length--
|
length--
|
||||||
return old
|
return old
|
||||||
@@ -249,7 +249,7 @@ actual class ArrayList<E> private constructor(
|
|||||||
if (backing != null) {
|
if (backing != null) {
|
||||||
backing.removeRangeInternal(rangeOffset, rangeLength)
|
backing.removeRangeInternal(rangeOffset, rangeLength)
|
||||||
} else {
|
} else {
|
||||||
array.copyRange(fromIndex = rangeOffset + rangeLength, toIndex = length, destinationIndex = rangeOffset)
|
array.copyRangeTo(array, fromIndex = rangeOffset + rangeLength, toIndex = length, destinationIndex = rangeOffset)
|
||||||
array.resetRange(fromIndex = length - rangeLength, toIndex = length)
|
array.resetRange(fromIndex = length - rangeLength, toIndex = length)
|
||||||
}
|
}
|
||||||
length -= rangeLength
|
length -= rangeLength
|
||||||
@@ -272,7 +272,7 @@ actual class ArrayList<E> private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val removed = rangeLength - j
|
val removed = rangeLength - j
|
||||||
array.copyRange(fromIndex = rangeOffset + rangeLength, toIndex = length, destinationIndex = rangeOffset + j)
|
array.copyRangeTo(array, fromIndex = rangeOffset + rangeLength, toIndex = length, destinationIndex = rangeOffset + j)
|
||||||
array.resetRange(fromIndex = length - removed, toIndex = length)
|
array.resetRange(fromIndex = length - removed, toIndex = length)
|
||||||
length -= removed
|
length -= removed
|
||||||
return removed
|
return removed
|
||||||
|
|||||||
@@ -359,13 +359,6 @@ internal fun DoubleArray.copyRangeTo(destination: DoubleArray, fromIndex: Int, t
|
|||||||
internal fun BooleanArray.copyRangeTo(destination: BooleanArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
internal fun BooleanArray.copyRangeTo(destination: BooleanArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Copies a range of array elements at a specified [fromIndex] (inclusive) to [toIndex] (exclusive) range of indices
|
|
||||||
* to another part of this array starting at [destinationIndex].
|
|
||||||
*/
|
|
||||||
public fun <E> Array<E>.copyRange(fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
|
||||||
copyRangeTo(this, fromIndex, toIndex, destinationIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun <E> Collection<E>.collectionToString(): String {
|
internal fun <E> Collection<E>.collectionToString(): String {
|
||||||
val sb = StringBuilder(2 + size * 3)
|
val sb = StringBuilder(2 + size * 3)
|
||||||
|
|||||||
Reference in New Issue
Block a user