Skip to content

Commit

Permalink
don't copy and mutate array; instead track idx
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jul 27, 2023
1 parent 4d505c8 commit e65b7bc
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ private static boolean isStringAllUppercase(final String input) {
}

// 3 instructions, load "this" local var, getfield, return - TODO maybe if there is a CAST,
private static final List<IntPredicate> OPCODES_IN_ORDER = List.of(
i -> i == Opcodes.ALOAD, i -> i == Opcodes.GETFIELD, i -> i >= Opcodes.IRETURN && i <= Opcodes.RETURN);
private static final IntPredicate[] OPCODES_IN_ORDER = new IntPredicate[]{
i -> i == Opcodes.ALOAD, i -> i == Opcodes.GETFIELD, i -> i >= Opcodes.IRETURN && i <= Opcodes.RETURN};

private static @Nullable String suggestNameFromFluentGetter(
final AsmClassData owner, final AsmMethodData method, final MethodInsnNode insn) {
Expand All @@ -494,19 +494,19 @@ private static boolean isStringAllUppercase(final String input) {
if (!(method.descriptor().getReturnType() instanceof PrimitiveType)) {
return null;
}
final List<IntPredicate> codes = new ArrayList<>(OPCODES_IN_ORDER);
int opcodeIndex = 0;
for (final AbstractInsnNode methodInsn : method.getNode().instructions) {
if (methodInsn.getOpcode() == -1) {
continue;
}
if (codes.isEmpty()) {
if (opcodeIndex == OPCODES_IN_ORDER.length) {
return null;
}
if (codes.get(0).test(methodInsn.getOpcode())) {
codes.remove(0);
if (OPCODES_IN_ORDER[opcodeIndex].test(methodInsn.getOpcode())) {
opcodeIndex++;
}
}
if (!codes.isEmpty()) {
if (opcodeIndex != OPCODES_IN_ORDER.length) {
return null;
}
return method.name();
Expand Down

0 comments on commit e65b7bc

Please sign in to comment.