Improve argument validation in copyOfRange
Make copyOfRange implementation non-inline in order not to expose copyOfRangeToIndexCheck implementation detail. It will be possible to make the function non-inline itself later without that JvmName trick, when apiVersion 1.2 support is discontinued. #KT-19489
This commit is contained in:
@@ -622,71 +622,102 @@ public actual fun <T> Array<out T>.copyOf(newSize: Int): Array<T?> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
@Suppress("ACTUAL_WITHOUT_EXPECT", "NOTHING_TO_INLINE")
|
||||
public actual inline fun <T> Array<out T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T> {
|
||||
@Suppress("ACTUAL_WITHOUT_EXPECT")
|
||||
public actual fun <T> Array<out T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T> {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return this.asDynamic().slice(fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray {
|
||||
public actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return this.asDynamic().slice(fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray {
|
||||
public actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return this.asDynamic().slice(fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray {
|
||||
public actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return this.asDynamic().slice(fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
public actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return withType("LongArray", this.asDynamic().slice(fromIndex, toIndex))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray {
|
||||
public actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return this.asDynamic().slice(fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray {
|
||||
public actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return this.asDynamic().slice(fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
public actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return withType("BooleanArray", this.asDynamic().slice(fromIndex, toIndex))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array.
|
||||
* Returns a new array which is a copy of the specified range of the original array.
|
||||
*
|
||||
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
|
||||
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
|
||||
*/
|
||||
public actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray {
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
return withType("CharArray", this.asDynamic().slice(fromIndex, toIndex))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user