When by String constants:

Generate TABLESWITCH/LOOKUPSWITCH bytecode operation for when operator by String constants
This commit is contained in:
Denis Zharkov
2014-07-16 20:09:49 +04:00
committed by Evgeny Gerashchenko
parent 5a1c995b5c
commit d4cb822ee8
18 changed files with 511 additions and 75 deletions

View File

@@ -0,0 +1,15 @@
fun foo() : Int {
val x : String = "dsa"
when (x) {
"a" -> return 1
"b" -> return 1
"c" -> return 1
"d" -> return 1
"e" -> return 1
"f" -> return 1
else -> return -1
}
}
// 1 TABLESWITCH

View File

@@ -0,0 +1,11 @@
import kotlin.test.assertEquals
fun foo(x : String) : String {
when (x) {
"abc" -> return "abc"
"efg", "ghi", "abc" -> return "efg_ghi"
else -> return "other"
}
}
// 1 LOOKUPSWITCH

View File

@@ -0,0 +1,16 @@
import kotlin.test.assertEquals
fun foo(x : String) : String {
assert("abz]".hashCode() == "aby|".hashCode())
when (x) {
"abz]" -> return "abz"
"ghi" -> return "ghi"
"aby|" -> return "aby"
"abz]" -> return "fail"
}
return "other"
}
// 1 LOOKUPSWITCH

View File

@@ -0,0 +1,9 @@
fun foo(x : String) : String {
return when (x) {
"abc", "cde" -> "abc_cde"
"efg", "ghi" -> "efg_ghi"
else -> "other"
}
}
// 1 LOOKUPSWITCH

View File

@@ -0,0 +1,11 @@
fun foo(x : String) : String {
val y = "cde"
when (x) {
"abc", "${y}" -> return "abc_cde"
"e" + "fg", "ghi" -> return "efg_ghi"
}
return "other"
}
// 1 LOOKUPSWITCH

View File

@@ -0,0 +1,12 @@
fun foo(x : String) : String {
assert("abz]".hashCode() == "aby|".hashCode())
when (x) {
"abz]", "cde" -> return "abz_cde"
"aby|", "ghi" -> return "aby_ghi"
}
return "other"
}
// 1 LOOKUPSWITCH

View File

@@ -0,0 +1,19 @@
fun foo1(x : String) : String {
when (x) {
"abc", "cde" -> return "abc_cde"
"efg", "ghi" -> 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