Skip to content

Commit 8311d96

Browse files
committed
Optimize sorted() for primitive-type arrays
^KT-76423 Fixed
1 parent 5e98bf1 commit 8311d96

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6283,49 +6283,49 @@ public fun <T : Comparable<T>> Array<out T>.sorted(): List<T> {
62836283
* Returns a list of all elements sorted according to their natural sort order.
62846284
*/
62856285
public fun ByteArray.sorted(): List<Byte> {
6286-
return toTypedArray().apply { sort() }.asList()
6286+
return sortedArray().asList()
62876287
}
62886288

62896289
/**
62906290
* Returns a list of all elements sorted according to their natural sort order.
62916291
*/
62926292
public fun ShortArray.sorted(): List<Short> {
6293-
return toTypedArray().apply { sort() }.asList()
6293+
return sortedArray().asList()
62946294
}
62956295

62966296
/**
62976297
* Returns a list of all elements sorted according to their natural sort order.
62986298
*/
62996299
public fun IntArray.sorted(): List<Int> {
6300-
return toTypedArray().apply { sort() }.asList()
6300+
return sortedArray().asList()
63016301
}
63026302

63036303
/**
63046304
* Returns a list of all elements sorted according to their natural sort order.
63056305
*/
63066306
public fun LongArray.sorted(): List<Long> {
6307-
return toTypedArray().apply { sort() }.asList()
6307+
return sortedArray().asList()
63086308
}
63096309

63106310
/**
63116311
* Returns a list of all elements sorted according to their natural sort order.
63126312
*/
63136313
public fun FloatArray.sorted(): List<Float> {
6314-
return toTypedArray().apply { sort() }.asList()
6314+
return sortedArray().asList()
63156315
}
63166316

63176317
/**
63186318
* Returns a list of all elements sorted according to their natural sort order.
63196319
*/
63206320
public fun DoubleArray.sorted(): List<Double> {
6321-
return toTypedArray().apply { sort() }.asList()
6321+
return sortedArray().asList()
63226322
}
63236323

63246324
/**
63256325
* Returns a list of all elements sorted according to their natural sort order.
63266326
*/
63276327
public fun CharArray.sorted(): List<Char> {
6328-
return toTypedArray().apply { sort() }.asList()
6328+
return sortedArray().asList()
63296329
}
63306330

63316331
/**

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,12 @@ object Ordering : TemplateGroupBase() {
200200
return toMutableList().apply { sort() }
201201
"""
202202
}
203-
body(ArraysOfPrimitives) {
204-
"""
205-
return toTypedArray().apply { sort() }.asList()
206-
"""
207-
}
208203
body(ArraysOfUnsigned) {
209204
"""
210205
return copyOf().apply { sort() }.asList()
211206
"""
212207
}
213-
body(ArraysOfObjects) {
208+
body(ArraysOfPrimitives, ArraysOfObjects) {
214209
"""
215210
return sortedArray().asList()
216211
"""

0 commit comments

Comments
 (0)