mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
Make redundant null check optimization independent of boxing optimization algorithm.
Run DCE after each single redundant null check optimization pass.
This commit is contained in:
18
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifNullEqualsNull.kt
vendored
Normal file
18
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifNullEqualsNull.kt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test1() {
|
||||
val a = null
|
||||
|
||||
if (a != null) {
|
||||
println("X1")
|
||||
}
|
||||
|
||||
if (a == null) {
|
||||
println("X2")
|
||||
}
|
||||
}
|
||||
|
||||
// 0 IFNULL
|
||||
// 0 IFNONNULL
|
||||
// 0 X1
|
||||
// 1 X2
|
||||
19
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifNullEqualsNullInline.kt
vendored
Normal file
19
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifNullEqualsNullInline.kt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test1() {
|
||||
val n = null
|
||||
n.elvis { "X1" }
|
||||
"X2".elvis { "X3" }
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 IFNULL
|
||||
// 0 IFNONNULL
|
||||
// 1 X1
|
||||
// 1 X2
|
||||
// 0 X3
|
||||
|
||||
// FILE: inline.kt
|
||||
inline fun <T : Any> T?.elvis(rhs: () -> T): T = this ?: rhs()
|
||||
18
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifUnitEqualsNull.kt
vendored
Normal file
18
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifUnitEqualsNull.kt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test1() {
|
||||
val a = Unit
|
||||
|
||||
if (a != null) {
|
||||
println("X1")
|
||||
}
|
||||
|
||||
if (a == null) {
|
||||
println("X2")
|
||||
}
|
||||
}
|
||||
|
||||
// 0 IFNULL
|
||||
// 0 IFNONNULL
|
||||
// 1 X1
|
||||
// 0 X2
|
||||
18
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifUnitEqualsNullInline.kt
vendored
Normal file
18
compiler/testData/codegen/bytecodeText/nullCheckOptimization/ifUnitEqualsNullInline.kt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test1() {
|
||||
val u = Unit
|
||||
u.mapNullable({ "X1" }, { "X2" })
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 IFNULL
|
||||
// 0 IFNONNULL
|
||||
// 1 X1
|
||||
// 0 X2
|
||||
|
||||
// FILE: inline.kt
|
||||
inline fun <T : Any, R> T?.mapNullable(ifNotNull: (T) -> R, ifNull: () -> R) =
|
||||
if (this == null) ifNull() else ifNotNull(this)
|
||||
Reference in New Issue
Block a user