Move sorting implementations for Native to kotlin.collections
This commit is contained in:
committed by
Vasily Levchenko
parent
58000a20fd
commit
38ca63418d
@@ -1341,49 +1341,49 @@ public actual inline fun <T> Array<T>.plusElement(element: T): Array<T> {
|
|||||||
* Sorts the array in-place.
|
* Sorts the array in-place.
|
||||||
*/
|
*/
|
||||||
public actual fun IntArray.sort(): Unit {
|
public actual fun IntArray.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArray(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the array in-place.
|
* Sorts the array in-place.
|
||||||
*/
|
*/
|
||||||
public actual fun LongArray.sort(): Unit {
|
public actual fun LongArray.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArray(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the array in-place.
|
* Sorts the array in-place.
|
||||||
*/
|
*/
|
||||||
public actual fun ByteArray.sort(): Unit {
|
public actual fun ByteArray.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArray(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the array in-place.
|
* Sorts the array in-place.
|
||||||
*/
|
*/
|
||||||
public actual fun ShortArray.sort(): Unit {
|
public actual fun ShortArray.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArray(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the array in-place.
|
* Sorts the array in-place.
|
||||||
*/
|
*/
|
||||||
public actual fun DoubleArray.sort(): Unit {
|
public actual fun DoubleArray.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArray(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the array in-place.
|
* Sorts the array in-place.
|
||||||
*/
|
*/
|
||||||
public actual fun FloatArray.sort(): Unit {
|
public actual fun FloatArray.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArray(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the array in-place.
|
* Sorts the array in-place.
|
||||||
*/
|
*/
|
||||||
public actual fun CharArray.sort(): Unit {
|
public actual fun CharArray.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArray(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1392,7 +1392,7 @@ public actual fun CharArray.sort(): Unit {
|
|||||||
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
|
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
|
||||||
*/
|
*/
|
||||||
public actual fun <T : Comparable<T>> Array<out T>.sort(): Unit {
|
public actual fun <T : Comparable<T>> Array<out T>.sort(): Unit {
|
||||||
if (size > 1) kotlin.util.sortArrayComparable(this)
|
if (size > 1) sortArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1401,7 +1401,7 @@ public actual fun <T : Comparable<T>> Array<out T>.sort(): Unit {
|
|||||||
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
|
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
|
||||||
*/
|
*/
|
||||||
public actual fun <T> Array<out T>.sortWith(comparator: Comparator<in T>): Unit {
|
public actual fun <T> Array<out T>.sortWith(comparator: Comparator<in T>): Unit {
|
||||||
if (size > 1) kotlin.util.sortArrayWith(this, 0, size, comparator)
|
if (size > 1) sortArrayWith(this, 0, size, comparator)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,13 +8,9 @@
|
|||||||
|
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import kotlin.collections.*
|
|
||||||
import kotlin.internal.PureReifiable
|
import kotlin.internal.PureReifiable
|
||||||
import kotlin.native.internal.ExportTypeInfo
|
import kotlin.native.internal.ExportTypeInfo
|
||||||
import kotlin.native.internal.InlineConstructor
|
import kotlin.native.internal.InlineConstructor
|
||||||
import kotlin.util.sortArray
|
|
||||||
import kotlin.util.sortArrayComparable
|
|
||||||
import kotlin.util.sortArrayWith
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of bytes.
|
* An array of bytes.
|
||||||
|
|||||||
+2
-3
@@ -3,9 +3,8 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlin.util
|
package kotlin.collections
|
||||||
|
|
||||||
import kotlin.comparisons.*
|
|
||||||
|
|
||||||
private fun <T: Comparable<T>> mergeSort(array: Array<T>, start: Int, endInclusive: Int) {
|
private fun <T: Comparable<T>> mergeSort(array: Array<T>, start: Int, endInclusive: Int) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@@ -375,7 +374,7 @@ internal fun <T> sortArrayWith(
|
|||||||
* Sorts a subarray of [Comparable] elements specified by [fromIndex] (inclusive) and
|
* Sorts a subarray of [Comparable] elements specified by [fromIndex] (inclusive) and
|
||||||
* [toIndex] (exclusive) parameters using the qsort algorithm.
|
* [toIndex] (exclusive) parameters using the qsort algorithm.
|
||||||
*/
|
*/
|
||||||
internal fun <T: Comparable<T>> sortArrayComparable(array: Array<out T>) {
|
internal fun <T: Comparable<T>> sortArray(array: Array<out T>) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
mergeSort(array as Array<T>, 0, array.size - 1)
|
mergeSort(array as Array<T>, 0, array.size - 1)
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,7 @@
|
|||||||
package kotlin.collections
|
package kotlin.collections
|
||||||
|
|
||||||
import kotlin.native.internal.InlineConstructor
|
import kotlin.native.internal.InlineConstructor
|
||||||
import kotlin.collections.*
|
|
||||||
import kotlin.internal.PureReifiable
|
import kotlin.internal.PureReifiable
|
||||||
import kotlin.util.sortArrayComparable
|
|
||||||
import kotlin.util.sortArrayWith
|
|
||||||
import kotlin.util.sortArray
|
|
||||||
|
|
||||||
/** Returns the array if it's not `null`, or an empty array otherwise. */
|
/** Returns the array if it's not `null`, or an empty array otherwise. */
|
||||||
public actual inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: emptyArray<T>()
|
public actual inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: emptyArray<T>()
|
||||||
|
|||||||
Reference in New Issue
Block a user