JVM optimize out temporary variables in bytecode
This commit is contained in:
committed by
TeamCityServer
parent
bddfd086f6
commit
041773fd25
+1
-19
@@ -1,12 +1,3 @@
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface J {
|
||||
@NotNull
|
||||
public Integer foo();
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun Long.id() = this
|
||||
|
||||
fun Short.id() = this
|
||||
@@ -15,29 +6,20 @@ fun String.drop2() = if (length >= 2) subSequence(2, length) else null
|
||||
|
||||
fun doSimple1(s: String?) = s?.length == 3
|
||||
|
||||
fun doJava1(s: String?, j: J) = s?.length == j.foo()
|
||||
|
||||
fun doLongReceiver1(x: Long?) = x?.id() == 3L
|
||||
|
||||
fun doShortReceiver1(x: Short?, y: Short) = x?.id() == y
|
||||
|
||||
fun doChain1(s: String?) = s?.drop2()?.length == 1
|
||||
|
||||
fun doIf1(s: String?) =
|
||||
if (s?.length == 1) "A" else "B"
|
||||
|
||||
fun doSimple2(s: String?) = 3 == s?.length
|
||||
|
||||
fun doJava2(s: String?, j: J) = j.foo() == s?.length
|
||||
|
||||
fun doLongReceiver2(x: Long?) = 3L == x?.id()
|
||||
|
||||
fun doShortReceiver2(x: Short?, y: Short) = y == x?.id()
|
||||
|
||||
fun doChain2(s: String?) = 1 == s?.drop2()?.length
|
||||
|
||||
fun doIf2(s: String?) =
|
||||
if (1 == s?.length) "A" else "B"
|
||||
|
||||
// `doJava1`/`doJava2` box `s?.length` instead of unboxing `j.foo()`:
|
||||
// 2 valueOf
|
||||
// 0 valueOf
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun String.drop2() = if (length >= 2) subSequence(2, length) else null
|
||||
|
||||
fun doChain1(s: String?) = s?.drop2()?.length == 1
|
||||
|
||||
fun doChain2(s: String?) = 1 == s?.drop2()?.length
|
||||
|
||||
// 0 valueOf
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface J {
|
||||
@NotNull
|
||||
public Integer foo();
|
||||
}
|
||||
|
||||
// FILE: safeCallToPrimitiveEquality3.kt
|
||||
|
||||
fun doJava1(s: String?, j: J) = s?.length == j.foo()
|
||||
|
||||
fun doJava2(s: String?, j: J) = j.foo() == s?.length
|
||||
|
||||
// `doJava1`/`doJava2` box `s?.length` instead of unboxing `j.foo()`:
|
||||
// 2 valueOf
|
||||
Reference in New Issue
Block a user