When2Switch: generate ifnonnull check for nullable values before *switch-opcode

This commit is contained in:
Denis Zharkov
2014-07-17 11:59:58 +04:00
committed by Evgeny Gerashchenko
parent 706bbd7b72
commit 8d8c3d2b9e
11 changed files with 218 additions and 13 deletions

View File

@@ -0,0 +1,26 @@
enum class Season {
WINTER
SPRING
SUMMER
AUTUMN
}
fun foo1(x : Season?) : String {
when(x) {
Season.AUTUMN, Season.SPRING -> return "autumn_or_spring";
Season.SUMMER, null -> return "summer_or_null"
}
return "other"
}
fun foo2(x : Season?) : String {
when(x) {
Season.AUTUMN, Season.SPRING -> return "autumn_or_spring";
Season.SUMMER -> return "summer"
}
return "other"
}
// 2 TABLESWITCH

View File

@@ -0,0 +1,18 @@
fun foo1(x : String?) : String {
when (x) {
"abc", "cde" -> return "abc_cde"
"efg", "ghi", null -> return "efg_ghi"
}
return "other"
}
fun foo2(x : String?) : String {
when (x) {
"abc", "cde" -> return "abc_cde"
"efg", "ghi" -> return "efg_ghi"
else -> return "other"
}
}
// 2 LOOKUPSWITCH