In-place array sorting in JS.
This commit is contained in:
@@ -68,6 +68,7 @@ fun toPrimitiveArrays(): List<GenericFunction> =
|
||||
doc(ArraysOfObjects) { "Returns an array of ${primitive.name} containing all of the elements of this generic array." }
|
||||
doc(Collections) { "Returns an array of ${primitive.name} containing all of the elements of this collection." }
|
||||
returns(arrayType)
|
||||
// TODO: Use different implementations for JS
|
||||
body {
|
||||
"""
|
||||
val result = $arrayType(size())
|
||||
|
||||
@@ -131,6 +131,37 @@ fun specialJS(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("sort(comparison: (T, T) -> Int)") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
annotations("native")
|
||||
returns("Unit")
|
||||
doc { "Sorts the array inplace according to the order specified by the given [comparison] function." }
|
||||
body { "return noImpl" }
|
||||
}
|
||||
|
||||
templates add f("sort()") {
|
||||
only(ArraysOfPrimitives)
|
||||
only(numericPrimitives + PrimitiveType.Char)
|
||||
exclude(PrimitiveType.Long)
|
||||
returns("Unit")
|
||||
doc { "Sorts the array inplace." }
|
||||
annotations("""library("primitiveArraySort")""")
|
||||
body { "return noImpl" }
|
||||
}
|
||||
|
||||
templates add f("sort()") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
only(PrimitiveType.Long)
|
||||
typeParam("T: Comparable<T>")
|
||||
returns("Unit")
|
||||
doc { "Sorts the array inplace." }
|
||||
body {
|
||||
"""
|
||||
sort { a: T, b: T -> a.compareTo(b) }
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return templates
|
||||
|
||||
Reference in New Issue
Block a user