Unify Array.sort and sortWith function templates between JVM and JS.

Introduce new inline-only overload Array<out T: Comparable<T>>.sort().
This commit is contained in:
Ilya Gorbunov
2016-12-07 08:10:07 +03:00
parent e890cb137f
commit 572a63f0e2
4 changed files with 211 additions and 188 deletions
+72 -72
View File
@@ -12850,6 +12850,78 @@ public inline fun CharArray.asList(): List<Char> {
return this.unsafeCast<Array<Char>>().asList()
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun IntArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
public fun LongArray.sort(): Unit {
if (size > 1)
sort { a: Long, b: Long -> a.compareTo(b) }
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun ByteArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun ShortArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun DoubleArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun FloatArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun CharArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place according to the natural order of its elements.
*/
public fun <T: Comparable<T>> Array<out T>.sort(): Unit {
if (size > 1)
sort { a: T, b: T -> a.compareTo(b) }
}
/**
* Sorts the array in-place according to the order specified by the given [comparator].
*/
public fun <T> Array<out T>.sortWith(comparator: Comparator<in T>): Unit {
if (size > 1)
sort { a, b -> comparator.compare(a, b) }
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
@@ -13328,70 +13400,6 @@ public inline fun <T> Array<out T>.plusElement(element: T): Array<T> {
return this.asDynamic().concat(arrayOf(element))
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun ByteArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun ShortArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun IntArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun FloatArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun DoubleArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
@library("primitiveArraySort")
public fun CharArray.sort(): Unit {
noImpl
}
/**
* Sorts the array in-place.
*/
public fun <T: Comparable<T>> Array<out T>.sort(): Unit {
if (size > 1)
sort { a: T, b: T -> a.compareTo(b) }
}
/**
* Sorts the array in-place.
*/
public fun LongArray.sort(): Unit {
if (size > 1)
sort { a: Long, b: Long -> a.compareTo(b) }
}
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@@ -13448,11 +13456,3 @@ public inline fun CharArray.sort(noinline comparison: (Char, Char) -> Int): Unit
asDynamic().sort(comparison)
}
/**
* Sorts the array in-place according to the order specified by the given [comparator] object.
*/
public fun <T> Array<out T>.sortWith(comparator: Comparator<in T>): Unit {
if (size > 1)
sort { a, b -> comparator.compare(a, b) }
}