JVM optimize out temporary variables in bytecode

This commit is contained in:
Dmitry Petrov
2021-08-13 12:38:20 +03:00
committed by TeamCityServer
parent bddfd086f6
commit 041773fd25
22 changed files with 964 additions and 44 deletions
@@ -0,0 +1,25 @@
fun Long.id() = this
fun Short.id() = this
fun String.drop2() = if (length >= 2) subSequence(2, length) else null
fun doSimple1(s: String?) = s?.length == 3
fun doLongReceiver1(x: Long?) = x?.id() == 3L
fun doShortReceiver1(x: Short?, y: Short) = x?.id() == y
fun doIf1(s: String?) =
if (s?.length == 1) "A" else "B"
fun doSimple2(s: String?) = 3 == s?.length
fun doLongReceiver2(x: Long?) = 3L == x?.id()
fun doShortReceiver2(x: Short?, y: Short) = y == x?.id()
fun doIf2(s: String?) =
if (1 == s?.length) "A" else "B"
// 0 valueOf