mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 00:21:26 +00:00
Specialize Comparable#compareTo for boxed primitives
Support Comparable#compareTo for boxed primitive in redundant boxing/unboxing analysis, along with CHECKCAST to java.lang.Comparable. Note that we can do that for Float and Double, too, because Float#compareTo(Float) and Double#compareTo(Double) are delegated to Float#compare(float, float) and Double#compare(double, double), respectively. Fuse specialized comparison for integers with conditional jumps if possible (both for Comparable#compareTo and Intrinsics#areEqual). #KT-11959 Fixed
This commit is contained in:
34
compiler/testData/codegen/bytecodeText/boxingOptimization/maxMinBy.kt
vendored
Normal file
34
compiler/testData/codegen/bytecodeText/boxingOptimization/maxMinBy.kt
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: list.kt
|
||||
val intList = listOf(1, 2, 3)
|
||||
val longList = listOf(1L, 2L, 3L)
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
val intListMin = intList.minBy { it } ?: -1
|
||||
if (intListMin != 1) return "Fail intListMin=$intListMin"
|
||||
|
||||
val intListMax = intList.maxBy { it } ?: -1
|
||||
if (intListMax != 3) return "Fail intListMax=$intListMax"
|
||||
|
||||
val longListMin = longList.minBy { it } ?: -1
|
||||
if (longListMin != 1L) return "Fail longListMin=$longListMin"
|
||||
|
||||
val longListMax = longList.maxBy { it } ?: -1
|
||||
if (longListMax != 3L) return "Fail longListMax=$longListMax"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// @BoxKt.class:
|
||||
// -- no boxing
|
||||
// 0 valueOf
|
||||
// -- no compareTo
|
||||
// 0 compareTo
|
||||
// -- comparisons are properly fused with conditional jumps
|
||||
// 0 ICONST_0
|
||||
// 1 IF_ICMPGE
|
||||
// 1 IF_ICMPLE
|
||||
// 4 LCMP
|
||||
// 1 IFGE
|
||||
// 1 IFLE
|
||||
Reference in New Issue
Block a user