From 58000a20fdc803d5bd77059b40a51180f52ce3ed Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 27 Dec 2018 18:34:19 +0300 Subject: [PATCH] Rewrite MutableList.sortWith to suppress warning instead of error Use available naturalOrder comparator in MutableList.sort() --- .../main/kotlin/kotlin/collections/MutableCollections.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt b/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt index 8c123a75946..fd2d44393a5 100644 --- a/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt @@ -5,14 +5,12 @@ package kotlin.collections -import kotlin.comparisons.* - /** * Sorts elements in the list in-place according to their natural sort order. * * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. */ -public actual fun > MutableList.sort(): Unit = sortWith(Comparator { a: T, b: T -> a.compareTo(b) }) +public actual fun > MutableList.sort(): Unit = sortWith(naturalOrder()) /** * Sorts elements in the list in-place according to the order specified with [comparator]. @@ -22,7 +20,7 @@ public actual fun > MutableList.sort(): Unit = sortWith(Com public actual fun MutableList.sortWith(comparator: Comparator): Unit { if (size > 1) { val it = listIterator() - val sortedArray = @Suppress("TYPE_PARAMETER_AS_REIFIED") toTypedArray().apply { sortWith(comparator) } + val sortedArray = @Suppress("UNCHECKED_CAST") (toTypedArray() as Array).apply { sortWith(comparator) } for (v in sortedArray) { it.next() it.set(v)