JVM_IR KT-48435 use Java-like counter loop when possible
This commit is contained in:
committed by
TeamCityServer
parent
d4c91c96d3
commit
1c1b9547c1
@@ -0,0 +1,16 @@
|
||||
const val N = 10
|
||||
|
||||
fun sumUntil6(): Int {
|
||||
var sum = 0
|
||||
for (i in 0..N) {
|
||||
if (i == 6) break
|
||||
sum += i
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = sumUntil6()
|
||||
if (test != 15) return "Failed: $test"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
const val N = 10
|
||||
|
||||
fun sumOdds(): Int {
|
||||
var sum = 0
|
||||
for (i in 0..N) {
|
||||
if (i%2 == 0) continue
|
||||
sum += i
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = sumOdds()
|
||||
if (test != 25) return "Failed: $test"
|
||||
return "OK"
|
||||
}
|
||||
Vendored
-3
@@ -9,7 +9,4 @@ abstract class A8 : MutableCollection<Any> {
|
||||
// 0 INSTANCEOF
|
||||
|
||||
/* Only 1 null check should be within the contains method */
|
||||
// JVM_TEMPLATES:
|
||||
// 1 IFNULL
|
||||
// JVM_IR_TEMPLATES:
|
||||
// 1 IFNONNULL
|
||||
|
||||
Vendored
-3
@@ -9,7 +9,4 @@ abstract class A<T : Any> : MutableCollection<T> {
|
||||
// 0 INSTANCEOF
|
||||
|
||||
/* Only 1 null check should be within the contains method (because T is not nullable) */
|
||||
// JVM_TEMPLATES:
|
||||
// 1 IFNULL
|
||||
// JVM_IR_TEMPLATES:
|
||||
// 1 IFNONNULL
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ class A(val x: String) {
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// Optimization not implemented
|
||||
// 8 IFNULL
|
||||
// 0 IFNONNULL
|
||||
// 4 IFNULL
|
||||
// 4 IFNONNULL
|
||||
// 2 ACONST_NULL
|
||||
|
||||
// JVM_IR_TEMPLATES
|
||||
|
||||
+1
-1
@@ -26,6 +26,6 @@ fun box(): String {
|
||||
// LOCAL VARIABLES JVM
|
||||
// test.kt:5 box: i:int=0:int
|
||||
// LOCAL VARIABLES JVM_IR
|
||||
// test.kt:5 box:
|
||||
// test.kt:5 box: i:int=0:int
|
||||
// LOCAL VARIABLES
|
||||
// test.kt:14 box:
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ fun box() {
|
||||
// test.kt:24 compute:
|
||||
// test.kt:25 compute: s2:java.lang.String="NOPE":java.lang.String
|
||||
// test.kt:26 compute: s2:java.lang.String="NOPE":java.lang.String, j:int=0:int
|
||||
// test.kt:25 compute: s2:java.lang.String="OK":java.lang.String
|
||||
// test.kt:25 compute: s2:java.lang.String="OK":java.lang.String, j:int=0:int
|
||||
// test.kt:28 compute: s2:java.lang.String="OK":java.lang.String
|
||||
// test.kt:34 box:
|
||||
// test.kt:35 box: result:java.lang.String="NON_LOCAL_RETURN":java.lang.String
|
||||
|
||||
Reference in New Issue
Block a user