From 38ca63418d617079bf12b2b274c5ff33831aa9ba Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 27 Dec 2018 18:36:11 +0300 Subject: [PATCH] Move sorting implementations for Native to kotlin.collections --- .../src/main/kotlin/generated/_ArraysNative.kt | 18 +++++++++--------- runtime/src/main/kotlin/kotlin/Arrays.kt | 4 ---- .../Sort.kt => collections/ArraySorting.kt} | 5 ++--- .../main/kotlin/kotlin/collections/Arrays.kt | 4 ---- 4 files changed, 11 insertions(+), 20 deletions(-) rename runtime/src/main/kotlin/kotlin/{util/Sort.kt => collections/ArraySorting.kt} (98%) diff --git a/runtime/src/main/kotlin/generated/_ArraysNative.kt b/runtime/src/main/kotlin/generated/_ArraysNative.kt index 5b32efd1c57..b1665b398be 100644 --- a/runtime/src/main/kotlin/generated/_ArraysNative.kt +++ b/runtime/src/main/kotlin/generated/_ArraysNative.kt @@ -1341,49 +1341,49 @@ public actual inline fun Array.plusElement(element: T): Array { * Sorts the array in-place. */ public actual fun IntArray.sort(): Unit { - if (size > 1) kotlin.util.sortArray(this) + if (size > 1) sortArray(this) } /** * Sorts the array in-place. */ public actual fun LongArray.sort(): Unit { - if (size > 1) kotlin.util.sortArray(this) + if (size > 1) sortArray(this) } /** * Sorts the array in-place. */ public actual fun ByteArray.sort(): Unit { - if (size > 1) kotlin.util.sortArray(this) + if (size > 1) sortArray(this) } /** * Sorts the array in-place. */ public actual fun ShortArray.sort(): Unit { - if (size > 1) kotlin.util.sortArray(this) + if (size > 1) sortArray(this) } /** * Sorts the array in-place. */ public actual fun DoubleArray.sort(): Unit { - if (size > 1) kotlin.util.sortArray(this) + if (size > 1) sortArray(this) } /** * Sorts the array in-place. */ public actual fun FloatArray.sort(): Unit { - if (size > 1) kotlin.util.sortArray(this) + if (size > 1) sortArray(this) } /** * Sorts the array in-place. */ 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. */ public actual fun > Array.sort(): Unit { - if (size > 1) kotlin.util.sortArrayComparable(this) + if (size > 1) sortArray(this) } /** @@ -1401,7 +1401,7 @@ public actual fun > Array.sort(): Unit { * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. */ public actual fun Array.sortWith(comparator: Comparator): Unit { - if (size > 1) kotlin.util.sortArrayWith(this, 0, size, comparator) + if (size > 1) sortArrayWith(this, 0, size, comparator) } /** diff --git a/runtime/src/main/kotlin/kotlin/Arrays.kt b/runtime/src/main/kotlin/kotlin/Arrays.kt index b89b9d99c55..ccced547ad9 100644 --- a/runtime/src/main/kotlin/kotlin/Arrays.kt +++ b/runtime/src/main/kotlin/kotlin/Arrays.kt @@ -8,13 +8,9 @@ package kotlin -import kotlin.collections.* import kotlin.internal.PureReifiable import kotlin.native.internal.ExportTypeInfo import kotlin.native.internal.InlineConstructor -import kotlin.util.sortArray -import kotlin.util.sortArrayComparable -import kotlin.util.sortArrayWith /** * An array of bytes. diff --git a/runtime/src/main/kotlin/kotlin/util/Sort.kt b/runtime/src/main/kotlin/kotlin/collections/ArraySorting.kt similarity index 98% rename from runtime/src/main/kotlin/kotlin/util/Sort.kt rename to runtime/src/main/kotlin/kotlin/collections/ArraySorting.kt index cb649982d9c..3b92da34a39 100644 --- a/runtime/src/main/kotlin/kotlin/util/Sort.kt +++ b/runtime/src/main/kotlin/kotlin/collections/ArraySorting.kt @@ -3,9 +3,8 @@ * that can be found in the LICENSE file. */ -package kotlin.util +package kotlin.collections -import kotlin.comparisons.* private fun > mergeSort(array: Array, start: Int, endInclusive: Int) { @Suppress("UNCHECKED_CAST") @@ -375,7 +374,7 @@ internal fun sortArrayWith( * Sorts a subarray of [Comparable] elements specified by [fromIndex] (inclusive) and * [toIndex] (exclusive) parameters using the qsort algorithm. */ -internal fun > sortArrayComparable(array: Array) { +internal fun > sortArray(array: Array) { @Suppress("UNCHECKED_CAST") mergeSort(array as Array, 0, array.size - 1) } diff --git a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt index d4b6e4352bc..25871476ff6 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt @@ -6,11 +6,7 @@ package kotlin.collections import kotlin.native.internal.InlineConstructor -import kotlin.collections.* 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. */ public actual inline fun Array?.orEmpty(): Array = this ?: emptyArray()