mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Optimize range operations for 'until' extension from stdlib (KT-9900)
NB: for-in-until loop is generated as precondition loop, because the corresponding range is right-exclusive (and thus we have no problems with integer overflows).
This commit is contained in:
16
compiler/testData/codegen/bytecodeText/forLoop/forInUntil.kt
vendored
Normal file
16
compiler/testData/codegen/bytecodeText/forLoop/forInUntil.kt
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): Int {
|
||||
var sum = 0
|
||||
for (i in 1 until 6) {
|
||||
sum = sum * 10 + i
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
// 0 getEnd
|
||||
// 0 getFirst
|
||||
// 0 getLast
|
||||
// 1 IF
|
||||
@@ -1,6 +1,7 @@
|
||||
fun Int.until(other: Int) = this..other - 1
|
||||
fun foo() {
|
||||
for (i in 1 until 2) {
|
||||
val range = 1 until 2
|
||||
for (i in range) {
|
||||
}
|
||||
|
||||
for (i in 1..2 step 4) {}
|
||||
|
||||
Reference in New Issue
Block a user