Skip to content

Commit a714281

Browse files
committed
Don't create unnecessary array copies in sortedDescending()
1 parent b81293a commit a714281

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

libraries/stdlib/common/src/generated/_Arrays.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6699,49 +6699,49 @@ public fun <T : Comparable<T>> Array<out T>.sortedDescending(): List<T> {
66996699
* Returns a list of all elements sorted descending according to their natural sort order.
67006700
*/
67016701
public fun ByteArray.sortedDescending(): List<Byte> {
6702-
return copyOf().apply { sort() }.reversed()
6702+
return sortedArrayDescending().asList()
67036703
}
67046704

67056705
/**
67066706
* Returns a list of all elements sorted descending according to their natural sort order.
67076707
*/
67086708
public fun ShortArray.sortedDescending(): List<Short> {
6709-
return copyOf().apply { sort() }.reversed()
6709+
return sortedArrayDescending().asList()
67106710
}
67116711

67126712
/**
67136713
* Returns a list of all elements sorted descending according to their natural sort order.
67146714
*/
67156715
public fun IntArray.sortedDescending(): List<Int> {
6716-
return copyOf().apply { sort() }.reversed()
6716+
return sortedArrayDescending().asList()
67176717
}
67186718

67196719
/**
67206720
* Returns a list of all elements sorted descending according to their natural sort order.
67216721
*/
67226722
public fun LongArray.sortedDescending(): List<Long> {
6723-
return copyOf().apply { sort() }.reversed()
6723+
return sortedArrayDescending().asList()
67246724
}
67256725

67266726
/**
67276727
* Returns a list of all elements sorted descending according to their natural sort order.
67286728
*/
67296729
public fun FloatArray.sortedDescending(): List<Float> {
6730-
return copyOf().apply { sort() }.reversed()
6730+
return sortedArrayDescending().asList()
67316731
}
67326732

67336733
/**
67346734
* Returns a list of all elements sorted descending according to their natural sort order.
67356735
*/
67366736
public fun DoubleArray.sortedDescending(): List<Double> {
6737-
return copyOf().apply { sort() }.reversed()
6737+
return sortedArrayDescending().asList()
67386738
}
67396739

67406740
/**
67416741
* Returns a list of all elements sorted descending according to their natural sort order.
67426742
*/
67436743
public fun CharArray.sortedDescending(): List<Char> {
6744-
return copyOf().apply { sort() }.reversed()
6744+
return sortedArrayDescending().asList()
67456745
}
67466746

67476747
/**

libraries/stdlib/common/src/generated/_UArrays.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,7 +3155,7 @@ public fun UShortArray.sortedArrayDescending(): UShortArray {
31553155
@SinceKotlin("1.3")
31563156
@ExperimentalUnsignedTypes
31573157
public fun UIntArray.sortedDescending(): List<UInt> {
3158-
return copyOf().apply { sort() }.reversed()
3158+
return sortedArrayDescending().asList()
31593159
}
31603160

31613161
/**
@@ -3166,7 +3166,7 @@ public fun UIntArray.sortedDescending(): List<UInt> {
31663166
@SinceKotlin("1.3")
31673167
@ExperimentalUnsignedTypes
31683168
public fun ULongArray.sortedDescending(): List<ULong> {
3169-
return copyOf().apply { sort() }.reversed()
3169+
return sortedArrayDescending().asList()
31703170
}
31713171

31723172
/**
@@ -3177,7 +3177,7 @@ public fun ULongArray.sortedDescending(): List<ULong> {
31773177
@SinceKotlin("1.3")
31783178
@ExperimentalUnsignedTypes
31793179
public fun UByteArray.sortedDescending(): List<UByte> {
3180-
return copyOf().apply { sort() }.reversed()
3180+
return sortedArrayDescending().asList()
31813181
}
31823182

31833183
/**
@@ -3188,7 +3188,7 @@ public fun UByteArray.sortedDescending(): List<UByte> {
31883188
@SinceKotlin("1.3")
31893189
@ExperimentalUnsignedTypes
31903190
public fun UShortArray.sortedDescending(): List<UShort> {
3191-
return copyOf().apply { sort() }.reversed()
3191+
return sortedArrayDescending().asList()
31923192
}
31933193

31943194
/**

libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ object Ordering : TemplateGroupBase() {
305305
}
306306
body(ArraysOfPrimitives, ArraysOfUnsigned) {
307307
"""
308-
return copyOf().apply { sort() }.reversed()
308+
return sortedArrayDescending().asList()
309309
"""
310310
}
311311

0 commit comments

Comments
 (0)