mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Support Long and Char in const-bounded counter loop generation
If the loop end value is a compile-time constant (best we can do now), and it is safe to iterate over a given range using "naive" for loop (using '<=' or '>=' in loop condition), generate such loops for Longs and Chars as well Ints (Bytes, Shorts).
This commit is contained in:
12
compiler/testData/codegen/bytecodeText/forLoop/forInRangeToCharConst.kt
vendored
Normal file
12
compiler/testData/codegen/bytecodeText/forLoop/forInRangeToCharConst.kt
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
const val N = 'Z'
|
||||
|
||||
fun test(): Int {
|
||||
var sum = 0
|
||||
for (i in 'A' .. N) {
|
||||
sum += i.toInt()
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
// 0 IF_ICMPEQ
|
||||
// 1 IF_ICMPGT
|
||||
@@ -9,4 +9,4 @@ fun test(): Int {
|
||||
}
|
||||
|
||||
// 0 IF_ICMPEQ
|
||||
// 1 IF_ICMPGE
|
||||
// 1 IF_ICMPGT
|
||||
13
compiler/testData/codegen/bytecodeText/forLoop/forInRangeToLongConst.kt
vendored
Normal file
13
compiler/testData/codegen/bytecodeText/forLoop/forInRangeToLongConst.kt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
const val N = 42L
|
||||
|
||||
fun test(): Long {
|
||||
var sum = 0L
|
||||
for (i in 1L .. N) {
|
||||
sum += i
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
// 1 LCMP
|
||||
// 0 IFEQ
|
||||
// 1 IFGT
|
||||
@@ -29,5 +29,4 @@ fun box(): String {
|
||||
// 0 getFirst
|
||||
// 0 getLast
|
||||
// 0 getStep
|
||||
// 2 IF_ICMPEQ
|
||||
// ^ 1 for char progression, 1 for long progression
|
||||
// 0 IF_ICMPEQ
|
||||
Reference in New Issue
Block a user