diff --git a/plugins/kotlin/base/util/src/org/jetbrains/kotlin/util/CollectionUtils.kt b/plugins/kotlin/base/util/src/org/jetbrains/kotlin/util/CollectionUtils.kt index 90e27725554f..52d14eed490c 100644 --- a/plugins/kotlin/base/util/src/org/jetbrains/kotlin/util/CollectionUtils.kt +++ b/plugins/kotlin/base/util/src/org/jetbrains/kotlin/util/CollectionUtils.kt @@ -50,15 +50,6 @@ fun List.takeWhileInclusive(predicate: (T) -> Boolean): List { return slice(0..inclusiveIndex) } -/** - * Sorted by [selector] or preserves the order for elements where [selector] returns the same result - */ -@ApiStatus.Internal -fun > Sequence.sortedConservativelyBy(selector: (T) -> R?): Sequence = - withIndex() - .sortedWith(compareBy({ (_, value) -> selector(value) }, IndexedValue::index)) - .map(IndexedValue::value) - private fun Sequence.cycle(): Sequence = sequence { while (true) yieldAll(this@cycle) } /** diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/ReorderParametersFix.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/ReorderParametersFix.kt index 1556faa04060..7e047d640074 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/ReorderParametersFix.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/ReorderParametersFix.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.util.graph.DirectedGraph import org.jetbrains.kotlin.util.graph.sortTopologically -import org.jetbrains.kotlin.util.sortedConservativelyBy class ReorderParametersFix( element: KtNamedFunction, @@ -80,7 +79,9 @@ class ReorderParametersFix( .associate { (topologicalIndex, parameterName) -> parameterName to topologicalIndex } val sortedParameters = parameters.asSequence() .mapNotNull(KtParameter::getName) - .sortedConservativelyBy(parameterToTopologicalIndex::getValue) + // `sortedBy` is stable (It's written in the KDoc). + // It means that equal elements preserve their order relative to each other after sorting. + .sortedBy(parameterToTopologicalIndex::getValue) .toList() if (sortedParameters.size != parameters.size) return null return ReorderParametersFix(function, sortedParameters)