Allow to specify optional from and to indices for filling an array.
#KT-8382 Fixed
This commit is contained in:
@@ -409,64 +409,64 @@ public fun <T> Array<T>.copyOfRange(from: Int, to: Int): Array<T> {
|
|||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun BooleanArray.fill(element: Boolean): Unit {
|
public fun BooleanArray.fill(element: Boolean, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun ByteArray.fill(element: Byte): Unit {
|
public fun ByteArray.fill(element: Byte, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun CharArray.fill(element: Char): Unit {
|
public fun CharArray.fill(element: Char, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun DoubleArray.fill(element: Double): Unit {
|
public fun DoubleArray.fill(element: Double, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun FloatArray.fill(element: Float): Unit {
|
public fun FloatArray.fill(element: Float, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun IntArray.fill(element: Int): Unit {
|
public fun IntArray.fill(element: Int, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun LongArray.fill(element: Long): Unit {
|
public fun LongArray.fill(element: Long, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun ShortArray.fill(element: Short): Unit {
|
public fun ShortArray.fill(element: Short, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills original array with the provided value.
|
* Fills original array with the provided value.
|
||||||
*/
|
*/
|
||||||
public fun <T> Array<T>.fill(element: T): Unit {
|
public fun <T> Array<T>.fill(element: T, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -83,13 +83,13 @@ fun specialJVM(): List<GenericFunction> {
|
|||||||
annotations(InvariantArraysOfObjects) { """platformName("mutableCopyOf")"""}
|
annotations(InvariantArraysOfObjects) { """platformName("mutableCopyOf")"""}
|
||||||
}
|
}
|
||||||
|
|
||||||
templates add f("fill(element: T)") {
|
templates add f("fill(element: T, fromIndex: Int = 0, toIndex: Int = size())") {
|
||||||
only(InvariantArraysOfObjects, ArraysOfPrimitives)
|
only(InvariantArraysOfObjects, ArraysOfPrimitives)
|
||||||
doc { "Fills original array with the provided value." }
|
doc { "Fills original array with the provided value." }
|
||||||
returns { "Unit" }
|
returns { "Unit" }
|
||||||
body {
|
body {
|
||||||
"""
|
"""
|
||||||
Arrays.fill(this, element)
|
Arrays.fill(this, fromIndex, toIndex, element)
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user