d474f207e3
This patch optimizes the following pattern:
for (i in first..last step st) { ... }
In this case we need to create a Progression object and then call its
iterator() method causing at least 2 allocation per loop. This change
replaces such loops with the following constuction:
var inductionVar = first
checkProgressionStep(step) // check if step > 0
last = getProgressionLastElement(first, last, step)
if (first <= last) {
do {
i = inductionVar
inductionVar += step
...
} while(i != last)
}
8 lines
402 B
Kotlin
8 lines
402 B
Kotlin
fun main(args: Array<String>) {
|
|
for (i in Int.MAX_VALUE - 1 .. Int.MAX_VALUE) { print(i); print(' ') }; println()
|
|
for (i in Int.MAX_VALUE - 1 until Int.MAX_VALUE) { print(i); print(' ') }; println()
|
|
for (i in Int.MIN_VALUE + 1 downTo Int.MIN_VALUE) { print(i); print(' ') }; println()
|
|
|
|
val M = Int.MAX_VALUE / 2
|
|
for (i in M + 4..M + 10 step M) { print(i); print(' ') }; println()
|
|
} |