Optimizations of When expression with int constants:

Added test with dense constants (tableswitch should be used)
This commit is contained in:
Denis Zharkov
2014-04-09 15:38:41 +04:00
committed by Evgeny Gerashchenko
parent 298742ae69
commit cb1e762fc4
2 changed files with 30 additions and 0 deletions
@@ -0,0 +1,25 @@
import java.util.ArrayList
fun dense(x: Int): Int {
return when (x) {
-4 -> 9
-1 -> 10
0 -> 11
1 -> 12
4 -> 13
5 -> 14
6 -> 15
7 -> 16
8 -> 17
9 -> 18
else -> 19
}
}
fun box(): String {
var result = (-5..10).map(::dense).makeString()
if (result != "19, 9, 19, 19, 10, 11, 12, 19, 19, 13, 14, 15, 16, 17, 18, 19") return "dense:" + result
return "OK"
}