Sorting optimizations: do not make excessive copies, introduce methods to sort the whole array.
#KT-9904 Fixed
This commit is contained in:
@@ -4725,56 +4725,56 @@ public fun ShortArray.sortDescending(): Unit {
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun <T : Comparable<T>> Array<out T>.sorted(): List<T> {
|
||||
return toArrayList().apply { sort() }
|
||||
return sortedArray().asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun ByteArray.sorted(): List<Byte> {
|
||||
return toArrayList().apply { sort() }
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun CharArray.sorted(): List<Char> {
|
||||
return toArrayList().apply { sort() }
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun DoubleArray.sorted(): List<Double> {
|
||||
return toArrayList().apply { sort() }
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun FloatArray.sorted(): List<Float> {
|
||||
return toArrayList().apply { sort() }
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun IntArray.sorted(): List<Int> {
|
||||
return toArrayList().apply { sort() }
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun LongArray.sorted(): List<Long> {
|
||||
return toArrayList().apply { sort() }
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to their natural sort order.
|
||||
*/
|
||||
public fun ShortArray.sorted(): List<Short> {
|
||||
return toArrayList().apply { sort() }
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5099,63 +5099,63 @@ public fun ShortArray.sortedDescending(): List<Short> {
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun <T> Array<out T>.sortedWith(comparator: Comparator<in T>): List<T> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return sortedArrayWith(comparator).asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun BooleanArray.sortedWith(comparator: Comparator<in Boolean>): List<Boolean> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun ByteArray.sortedWith(comparator: Comparator<in Byte>): List<Byte> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun CharArray.sortedWith(comparator: Comparator<in Char>): List<Char> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun DoubleArray.sortedWith(comparator: Comparator<in Double>): List<Double> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun FloatArray.sortedWith(comparator: Comparator<in Float>): List<Float> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun IntArray.sortedWith(comparator: Comparator<in Int>): List<Int> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun LongArray.sortedWith(comparator: Comparator<in Long>): List<Long> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements sorted according to the specified [comparator].
|
||||
*/
|
||||
public fun ShortArray.sortedWith(comparator: Comparator<in Short>): List<Short> {
|
||||
return toArrayList().apply { sortWith(comparator) }
|
||||
return toTypedArray().apply { sortWith(comparator) }.asList()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -11447,7 +11447,71 @@ public operator fun <T> Array<T>.plus(element: T): Array<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun <T> Array<out T>.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun ByteArray.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun CharArray.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun DoubleArray.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun FloatArray.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun IntArray.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun LongArray.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun ShortArray.sort(): Unit {
|
||||
if (size > 1) Arrays.sort(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun <T> Array<out T>.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11455,7 +11519,7 @@ public fun <T> Array<out T>.sort(fromIndex: Int = 0, toIndex: Int = size()): Uni
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11463,7 +11527,7 @@ public fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11471,7 +11535,7 @@ public fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11479,7 +11543,7 @@ public fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11487,7 +11551,7 @@ public fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11495,7 +11559,7 @@ public fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11503,7 +11567,7 @@ public fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts a range in the array in-place.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
@@ -11511,7 +11575,15 @@ public fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace.
|
||||
* Sorts the array in-place with the given [comparator].
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun <T> Array<out T>.sortWith(comparator: Comparator<in T>): Unit {
|
||||
if (size > 1) Arrays.sort(this, comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts a range in the array in-place with the given [comparator].
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public fun <T> Array<out T>.sortWith(comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
|
||||
Reference in New Issue
Block a user