Spill stack for inline functions only if it's required
Stack should be spilled before inline function call and restored after call only if one of the following conditions is met: - inline function is a suspend function - inline function has try-catch blocks - inline function has loops (backward jumps) Note that there're quite some "simple" inline functions in Kotlin stdlib besides run/let/with/apply. For example, many string operations are implemented as inline wrappers over Java method calls.
This commit is contained in:
+9
-4
@@ -1,17 +1,22 @@
|
||||
inline fun <T> runAfterLoop(fn: () -> T): T {
|
||||
for (i in 1..2);
|
||||
return fn()
|
||||
}
|
||||
|
||||
fun bar() : Boolean = true
|
||||
|
||||
fun foobar(x: Boolean, y: String, z: String) = x.toString() + y + z
|
||||
|
||||
inline fun foo() = "-"
|
||||
inline fun foo() = runAfterLoop { "-" }
|
||||
|
||||
fun test() {
|
||||
val result = foobar(if (1 == 1) true else bar(), foo(), "OK")
|
||||
}
|
||||
|
||||
// 1 ISTORE
|
||||
// 2 ILOAD
|
||||
// 7 ISTORE
|
||||
// 8 ILOAD
|
||||
// 2 ASTORE
|
||||
// 5 ALOAD
|
||||
// 7 ALOAD
|
||||
// 1 MAXLOCALS = 3
|
||||
// 1 MAXLOCALS = 4
|
||||
// 0 InlineMarker
|
||||
|
||||
Reference in New Issue
Block a user