Files
kotlin-fork/compiler/testData/codegen/bytecodeText/nullCheckOptimization/safeCallAndElvisChains.kt
T
pyos 85b4668b7c JVM_IR: optimize more if-null chains
1. consider reads of fields from the same file "stable" just like
    functions, i.e. assume their nullability information is correct
 2. apply if-null fusion repeatedly until the subject is no longer a
    nested if-null expression
2021-04-13 11:48:36 +03:00

19 lines
543 B
Kotlin
Vendored

class A(val x: String) {
fun y() = x
// Both `x` and `y()` assumed to respect their nullability information,
// so only `a` and `b` need to be checked.
fun foo1(a: A?, b: A?) = a?.x ?: b?.x ?: x // if (a == null) if (b == null) x else b.x else a.x
fun foo2(a: A?, b: A?) = a?.y() ?: b?.y() ?: y() // if (a == null) if (b == null) y() else b.y() else a.y()
}
// JVM_TEMPLATES
// Optimization not implemented
// 8 IFNULL
// 0 IFNONNULL
// 2 ACONST_NULL
// JVM_IR_TEMPLATES
// 0 IFNULL
// 4 IFNONNULL
// 0 ACONST_NULL