|
49 | 49 | import static org.codehaus.groovy.ast.ClassHelper.isPrimitiveVoid; |
50 | 50 | import static org.objectweb.asm.Opcodes.ACONST_NULL; |
51 | 51 | import static org.objectweb.asm.Opcodes.ALOAD; |
52 | | -import static org.objectweb.asm.Opcodes.BIPUSH; |
53 | 52 | import static org.objectweb.asm.Opcodes.CHECKCAST; |
54 | 53 | import static org.objectweb.asm.Opcodes.D2F; |
55 | 54 | import static org.objectweb.asm.Opcodes.D2I; |
56 | 55 | import static org.objectweb.asm.Opcodes.D2L; |
57 | | -import static org.objectweb.asm.Opcodes.DCONST_0; |
58 | | -import static org.objectweb.asm.Opcodes.DCONST_1; |
59 | 56 | import static org.objectweb.asm.Opcodes.DUP; |
60 | 57 | import static org.objectweb.asm.Opcodes.DUP2; |
61 | 58 | import static org.objectweb.asm.Opcodes.DUP2_X1; |
|
64 | 61 | import static org.objectweb.asm.Opcodes.F2D; |
65 | 62 | import static org.objectweb.asm.Opcodes.F2I; |
66 | 63 | import static org.objectweb.asm.Opcodes.F2L; |
67 | | -import static org.objectweb.asm.Opcodes.FCONST_0; |
68 | | -import static org.objectweb.asm.Opcodes.FCONST_1; |
69 | | -import static org.objectweb.asm.Opcodes.FCONST_2; |
70 | 64 | import static org.objectweb.asm.Opcodes.GETSTATIC; |
71 | 65 | import static org.objectweb.asm.Opcodes.I2B; |
72 | 66 | import static org.objectweb.asm.Opcodes.I2C; |
73 | 67 | import static org.objectweb.asm.Opcodes.I2D; |
74 | 68 | import static org.objectweb.asm.Opcodes.I2F; |
75 | 69 | import static org.objectweb.asm.Opcodes.I2L; |
76 | 70 | import static org.objectweb.asm.Opcodes.I2S; |
77 | | -import static org.objectweb.asm.Opcodes.ICONST_0; |
78 | | -import static org.objectweb.asm.Opcodes.ICONST_1; |
79 | 71 | import static org.objectweb.asm.Opcodes.INVOKESPECIAL; |
80 | 72 | import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; |
81 | 73 | import static org.objectweb.asm.Opcodes.L2D; |
82 | 74 | import static org.objectweb.asm.Opcodes.L2F; |
83 | 75 | import static org.objectweb.asm.Opcodes.L2I; |
84 | | -import static org.objectweb.asm.Opcodes.LCONST_0; |
85 | | -import static org.objectweb.asm.Opcodes.LCONST_1; |
86 | 76 | import static org.objectweb.asm.Opcodes.NEW; |
87 | 77 | import static org.objectweb.asm.Opcodes.POP; |
88 | 78 | import static org.objectweb.asm.Opcodes.POP2; |
@@ -165,11 +155,7 @@ public void castToBool(final int mark, final boolean emptyDefault) { |
165 | 155 | MethodVisitor mv = controller.getMethodVisitor(); |
166 | 156 | if (mark == size) { |
167 | 157 | // no element, so use emptyDefault |
168 | | - if (emptyDefault) { |
169 | | - mv.visitIntInsn(BIPUSH, 1); |
170 | | - } else { |
171 | | - mv.visitIntInsn(BIPUSH, 0); |
172 | | - } |
| 158 | + mv.visitLdcInsn(emptyDefault ? 1 : 0); |
173 | 159 | stack.add(null); |
174 | 160 | } else if (mark == size - 1) { |
175 | 161 | ClassNode last = stack.get(size - 1); |
@@ -585,42 +571,11 @@ private static void pushPrimitiveConstant(final MethodVisitor mv, final Object v |
585 | 571 | boolean isChar = isPrimitiveChar(type); |
586 | 572 | if (isInt || isShort || isByte || isChar) { |
587 | 573 | int val = isInt ? (Integer) value : isShort ? (Short) value : isChar ? (Character) value : (Byte) value; |
588 | | - BytecodeHelper.pushConstant(mv, val); |
589 | | - } else if (isPrimitiveLong(type)) { |
590 | | - if ((Long) value == 0L) { |
591 | | - mv.visitInsn(LCONST_0); |
592 | | - } else if ((Long) value == 1L) { |
593 | | - mv.visitInsn(LCONST_1); |
594 | | - } else { |
595 | | - mv.visitLdcInsn(value); |
596 | | - } |
597 | | - } else if (isPrimitiveFloat(type)) { |
598 | | - // GROOVY-9797: Use Float.equals to differentiate between positive and negative zero |
599 | | - if (value.equals(0f)) { |
600 | | - mv.visitInsn(FCONST_0); |
601 | | - } else if ((Float) value == 1f) { |
602 | | - mv.visitInsn(FCONST_1); |
603 | | - } else if ((Float) value == 2f) { |
604 | | - mv.visitInsn(FCONST_2); |
605 | | - } else { |
606 | | - mv.visitLdcInsn(value); |
607 | | - } |
608 | | - } else if (isPrimitiveDouble(type)) { |
609 | | - // GROOVY-9797: Use Double.equals to differentiate between positive and negative zero |
610 | | - if (value.equals(0d)) { |
611 | | - mv.visitInsn(DCONST_0); |
612 | | - } else if ((Double) value == 1d) { |
613 | | - mv.visitInsn(DCONST_1); |
614 | | - } else { |
615 | | - mv.visitLdcInsn(value); |
616 | | - } |
| 574 | + mv.visitLdcInsn(val); |
| 575 | + } else if (isPrimitiveLong(type) || isPrimitiveFloat(type) || isPrimitiveDouble(type)) { |
| 576 | + mv.visitLdcInsn(value); |
617 | 577 | } else if (isPrimitiveBoolean(type)) { |
618 | | - boolean b = (Boolean) value; |
619 | | - if (b) { |
620 | | - mv.visitInsn(ICONST_1); |
621 | | - } else { |
622 | | - mv.visitInsn(ICONST_0); |
623 | | - } |
| 578 | + mv.visitLdcInsn((Boolean) value ? 1 : 0); |
624 | 579 | } else { |
625 | 580 | mv.visitLdcInsn(value); |
626 | 581 | } |
@@ -729,7 +684,7 @@ public void load(final ClassNode type, final int idx) { |
729 | 684 | */ |
730 | 685 | public void pushBool(final boolean value) { |
731 | 686 | MethodVisitor mv = controller.getMethodVisitor(); |
732 | | - mv.visitInsn(value ? ICONST_1 : ICONST_0); |
| 687 | + mv.visitLdcInsn(value ? 1 : 0); |
733 | 688 | push(ClassHelper.boolean_TYPE); |
734 | 689 | } |
735 | 690 |
|
|
0 commit comments