Provide toTypedArray method for primitive arrays.
This commit is contained in:
@@ -21,6 +21,22 @@ fun specialJS(): List<GenericFunction> {
|
||||
body(ArraysOfPrimitives) {"""return (this as Array<T>).asList()"""}
|
||||
}
|
||||
|
||||
|
||||
templates add f("toTypedArray()") {
|
||||
only(ArraysOfPrimitives)
|
||||
returns("Array<T>")
|
||||
doc {
|
||||
"""
|
||||
Returns a *typed* object array containing all of the elements of this primitive array.
|
||||
"""
|
||||
}
|
||||
body {
|
||||
"""
|
||||
return copyOf() as Array<T>
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("copyOfRange(from: Int, to: Int)") {
|
||||
// TODO: Arguments checking as in java?
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
|
||||
@@ -216,5 +216,23 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("toTypedArray()") {
|
||||
only(ArraysOfPrimitives)
|
||||
returns("Array<T>")
|
||||
doc {
|
||||
"""
|
||||
Returns a *typed* object array containing all of the elements of this primitive array.
|
||||
"""
|
||||
}
|
||||
body {
|
||||
"""
|
||||
val result = arrayOfNulls<T>(size())
|
||||
for (index in indices)
|
||||
result[index] = this[index]
|
||||
return result as Array<T>
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
Reference in New Issue
Block a user