Skip to content

Commit 3a5449a

Browse files
committed
refactor(GLConstants): do integer arithmetic with Opcodes
1 parent 4dc472a commit 3a5449a

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
@@ -51,51 +51,28 @@ public GLConstants(ClassVisitor classVisitor) {
5151
super(classVisitor);
5252
}
5353

54-
private static boolean isICmp(int opcode) {
55-
switch (opcode) {
56-
case Opcodes.IF_ICMPEQ:
57-
case Opcodes.IF_ICMPGE:
58-
case Opcodes.IF_ICMPGT:
59-
case Opcodes.IF_ICMPLE:
60-
case Opcodes.IF_ICMPLT:
61-
case Opcodes.IF_ICMPNE:
62-
return true;
63-
}
64-
return false;
54+
private static boolean isICmp(final int opcode) {
55+
return opcode >= Opcodes.IF_ICMPEQ
56+
&& opcode <= Opcodes.IF_ICMPLE;
6557
}
6658

67-
public static Integer intValue(AbstractInsnNode insn) {
68-
if (insn.getOpcode() == Opcodes.ICONST_0) {
69-
return 0;
70-
}
71-
if (insn.getOpcode() == Opcodes.ICONST_1) {
72-
return 1;
73-
}
74-
if (insn.getOpcode() == Opcodes.ICONST_2) {
75-
return 2;
76-
}
77-
if (insn.getOpcode() == Opcodes.ICONST_3) {
78-
return 3;
79-
}
80-
if (insn.getOpcode() == Opcodes.ICONST_4) {
81-
return 4;
82-
}
83-
if (insn.getOpcode() == Opcodes.ICONST_5) {
84-
return 5;
85-
}
86-
if (insn.getOpcode() == Opcodes.ICONST_M1) {
87-
return -1;
88-
}
89-
if (insn.getOpcode() == Opcodes.SIPUSH || insn.getOpcode() == Opcodes.BIPUSH) {
90-
return ((IntInsnNode) insn).operand;
91-
}
92-
if (insn.getOpcode() == Opcodes.LDC) {
93-
LdcInsnNode ldc = (LdcInsnNode) insn;
94-
if (ldc.cst instanceof Integer) {
95-
return (Integer) ldc.cst;
96-
}
59+
public static Integer intValue(final AbstractInsnNode insn) {
60+
final int cnst = insn.getOpcode() - Opcodes.ICONST_0;
61+
if (cnst >= 0 && cnst <= 5) return cnst;
62+
63+
switch (insn.getOpcode()) {
64+
case Opcodes.ICONST_M1:
65+
return -1;
66+
case Opcodes.SIPUSH:
67+
case Opcodes.BIPUSH:
68+
return ((IntInsnNode) insn).operand;
69+
case Opcodes.LDC:
70+
final LdcInsnNode ldc = (LdcInsnNode) insn;
71+
if (ldc.cst instanceof Integer)
72+
return (Integer) ldc.cst;
73+
default:
74+
return null;
9775
}
98-
return null;
9976
}
10077

10178
public static FieldInsnNode getKeyboardInsn(int constant) {

0 commit comments

Comments
 (0)