diff --git a/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt b/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt index 4a934ea582e..6de07232967 100644 --- a/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/MutableCollections.kt @@ -258,17 +258,17 @@ private fun MutableCollection<*>.retainNothing(): Boolean { /** * Sorts elements in the list in-place according to their natural sort order. */ -@FixmeSorting -public fun > MutableList.sort(): Unit { - TODO() - //if (size > 1) java.util.Collections.sort(this) -} +public fun > MutableList.sort(): Unit = sortWith(Comparator { a: T, b: T -> a.compareTo(b) }) /** * Sorts elements in the list in-place according to the order specified with [comparator]. */ -@FixmeSorting public fun MutableList.sortWith(comparator: Comparator): Unit { - TODO() - //if (size > 1) java.util.Collections.sort(this, comparator) + if (size > 1) { + val it = listIterator() + for (v in toTypedArray().apply { sortWith(comparator) }) { + it.next() + it.set(v) + } + } }