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
|
||||
|
||||
Reference in New Issue
Block a user