mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup: drop unnecessary sortedConservativelyBy
It's unnecessary because default `sortedBy` in Kotlin is already stable GitOrigin-RevId: 98c9ca59fd51eee919bc30c797c5c050bbc55ca5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5ef8398f8b
commit
9c31aa87da
@@ -50,15 +50,6 @@ fun <T> List<T>.takeWhileInclusive(predicate: (T) -> Boolean): List<T> {
|
||||
return slice(0..inclusiveIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorted by [selector] or preserves the order for elements where [selector] returns the same result
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
fun <T, R : Comparable<R>> Sequence<T>.sortedConservativelyBy(selector: (T) -> R?): Sequence<T> =
|
||||
withIndex()
|
||||
.sortedWith(compareBy({ (_, value) -> selector(value) }, IndexedValue<T>::index))
|
||||
.map(IndexedValue<T>::value)
|
||||
|
||||
private fun <T> Sequence<T>.cycle(): Sequence<T> = sequence { while (true) yieldAll(this@cycle) }
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user