KT-3002 optimized ==/!=0

Optimize byte-code generation for integer comparisons != and ==.
Work done in Hackergarten Vienna.
Co-authored-by: Kilian Matt <kilian.matt@gmail.com>
This commit is contained in:
Rafael Cordones
2012-10-29 22:06:42 +01:00
committed by Alexander Udalov
parent d28c9e0eef
commit cb99f26807
2 changed files with 45 additions and 0 deletions
@@ -234,6 +234,22 @@ public class ControlStructuresTest extends CodegenTestCase {
blackBoxFile("regressions/kt237.jet");
}
public void testCompareToZero() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo(a: Int, b: Int): Boolean = a == 0 && b != 0 && 0 == a && 0 != b");
String text = generateToText();
/*
* Check that the we generate optimized byte-code!
*/
assertTrue(text.contains("IFEQ"));
assertTrue(text.contains("IFNE"));
assertFalse(text.contains("IF_ICMPEQ"));
assertFalse(text.contains("IF_ICMPNE"));
final Method main = generateFunction();
assertEquals(true, main.invoke(null, 0, 1));
assertEquals(false, main.invoke(null, 1, 0));
}
public void testCompareToNull() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo(a: String?, b: String?): Boolean = a == null && b !== null && null == a && null !== b");