Optimizations of When expression with int constants:
Added test with dense constants (tableswitch should be used)
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
298742ae69
commit
cb1e762fc4
@@ -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"
|
||||||
|
}
|
||||||
|
|
||||||
+5
@@ -1090,6 +1090,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/when"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/when"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("switchOptimizationDense.kt")
|
||||||
|
public void testSwitchOptimizationDense() throws Exception {
|
||||||
|
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/when/switchOptimizationDense.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("switchOptimizationMultipleConditions.kt")
|
@TestMetadata("switchOptimizationMultipleConditions.kt")
|
||||||
public void testSwitchOptimizationMultipleConditions() throws Exception {
|
public void testSwitchOptimizationMultipleConditions() throws Exception {
|
||||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/when/switchOptimizationMultipleConditions.kt");
|
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/when/switchOptimizationMultipleConditions.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user