Skip to content

Commit 725f731

Browse files
committed
refactor(GLConstants): do integer arithmetic with Opcodes
1 parent 5538581 commit 725f731

1 file changed

Lines changed: 19 additions & 42 deletions

File tree

src/main/java/org/mcphackers/mcp/tools/injector/GLConstants.java

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,51 +36,28 @@ public GLConstants(ClassVisitor classVisitor) {
3636
super(classVisitor);
3737
}
3838

39-
private static boolean isICmp(int opcode) {
40-
switch (opcode) {
41-
case Opcodes.IF_ICMPEQ:
42-
case Opcodes.IF_ICMPGE:
43-
case Opcodes.IF_ICMPGT:
44-
case Opcodes.IF_ICMPLE:
45-
case Opcodes.IF_ICMPLT:
46-
case Opcodes.IF_ICMPNE:
47-
return true;
48-
}
49-
return false;
39+
private static boolean isICmp(final int opcode) {
40+
return opcode >= Opcodes.IF_ICMPEQ
41+
&& opcode <= Opcodes.IF_ICMPLE;
5042
}
5143

52-
public static Integer intValue(AbstractInsnNode insn) {
53-
if (insn.getOpcode() == Opcodes.ICONST_0) {
54-
return 0;
55-
}
56-
if (insn.getOpcode() == Opcodes.ICONST_1) {
57-
return 1;
58-
}
59-
if (insn.getOpcode() == Opcodes.ICONST_2) {
60-
return 2;
61-
}
62-
if (insn.getOpcode() == Opcodes.ICONST_3) {
63-
return 3;
64-
}
65-
if (insn.getOpcode() == Opcodes.ICONST_4) {
66-
return 4;
67-
}
68-
if (insn.getOpcode() == Opcodes.ICONST_5) {
69-
return 5;
70-
}
71-
if (insn.getOpcode() == Opcodes.ICONST_M1) {
72-
return -1;
73-
}
74-
if (insn.getOpcode() == Opcodes.SIPUSH || insn.getOpcode() == Opcodes.BIPUSH) {
75-
return ((IntInsnNode) insn).operand;
76-
}
77-
if (insn.getOpcode() == Opcodes.LDC) {
78-
LdcInsnNode ldc = (LdcInsnNode) insn;
79-
if (ldc.cst instanceof Integer) {
80-
return (Integer) ldc.cst;
81-
}
44+
public static Integer intValue(final AbstractInsnNode insn) {
45+
final int cnst = insn.getOpcode() - Opcodes.ICONST_0;
46+
if (cnst >= 0 && cnst <= 5) return cnst;
47+
48+
switch (insn.getOpcode()) {
49+
case Opcodes.ICONST_M1:
50+
return -1;
51+
case Opcodes.SIPUSH:
52+
case Opcodes.BIPUSH:
53+
return ((IntInsnNode) insn).operand;
54+
case Opcodes.LDC:
55+
final LdcInsnNode ldc = (LdcInsnNode) insn;
56+
if (ldc.cst instanceof Integer)
57+
return (Integer) ldc.cst;
58+
default:
59+
return null;
8260
}
83-
return null;
8461
}
8562

8663
public static FieldInsnNode getKeyboardInsn(int constant) {

0 commit comments

Comments
 (0)