Common Array.fill for unsigned arrays, improve docs, native impl name
KT-32359
This commit is contained in:
@@ -1275,47 +1275,54 @@ object ArrayOps : TemplateGroupBase() {
|
||||
val f_fill = fn("fill(element: T, fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Fills original array with the provided value." }
|
||||
doc {
|
||||
"""
|
||||
Fills this array or its subrange with the specified [element] value.
|
||||
|
||||
@param fromIndex the start of the range (inclusive), 0 by default.
|
||||
@param toIndex the end of the range (exclusive), size of this array by default.
|
||||
|
||||
@throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
|
||||
@throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
|
||||
"""
|
||||
}
|
||||
returns("Unit")
|
||||
|
||||
on(Platform.JVM) {
|
||||
suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
body {
|
||||
"""
|
||||
java.util.Arrays.fill(this, fromIndex, toIndex, element)
|
||||
"""
|
||||
}
|
||||
}
|
||||
on(Platform.JS) {
|
||||
suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
body {
|
||||
"""
|
||||
if (fromIndex !in 0..size) {
|
||||
throw IndexOutOfBoundsException("fromIndex ${'$'}fromIndex out of range [0, ${'$'}size]")
|
||||
}
|
||||
if (toIndex > size) {
|
||||
throw IndexOutOfBoundsException("toIndex ${'$'}toIndex out of range [${'$'}fromIndex, ${'$'}size]")
|
||||
}
|
||||
require(fromIndex <= toIndex) { "fromIndex(${'$'}fromIndex) > toIndex(${'$'}toIndex)" }
|
||||
this.asDynamic().fill(element, fromIndex, toIndex);
|
||||
"""
|
||||
}
|
||||
}
|
||||
on(Platform.Native) {
|
||||
suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
body {
|
||||
"""
|
||||
arrayFill(this, element, fromIndex, toIndex)
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
specialFor(ArraysOfUnsigned) {
|
||||
val signedPrimitiveName = primitive!!.name.drop(1)
|
||||
body {
|
||||
"storage.fill(element.to$signedPrimitiveName(), fromIndex, toIndex)"
|
||||
}
|
||||
}
|
||||
|
||||
specialFor(InvariantArraysOfObjects, ArraysOfPrimitives) {
|
||||
on(Platform.JVM) {
|
||||
suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
body {
|
||||
"java.util.Arrays.fill(this, fromIndex, toIndex, element)"
|
||||
}
|
||||
}
|
||||
on(Platform.JS) {
|
||||
suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
since("1.3")
|
||||
body {
|
||||
"""
|
||||
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
|
||||
this.asDynamic().fill(element, fromIndex, toIndex);
|
||||
"""
|
||||
}
|
||||
}
|
||||
on(Platform.Native) {
|
||||
suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
since("1.3")
|
||||
body {
|
||||
"arrayFill(this, fromIndex, toIndex, element)"
|
||||
}
|
||||
}
|
||||
on(Platform.Common) {
|
||||
since("1.3")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val f_binarySearch = fn("binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
|
||||
Reference in New Issue
Block a user