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
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
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
|
||||
Reference in New Issue
Block a user