Skip to content

Commit 91a27bc

Browse files
committed
chore: make predicate static
1 parent 1c527c8 commit 91a27bc

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/main/java/ftbsc/lll/utils/PatternMatcher.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public static Builder builder() {
7171
* @param node the {@link MethodNode} to search
7272
* @return the InsnSequence object representing the matched pattern
7373
*/
74-
public InsnSequence find(MethodNode node) {
75-
return find(this.reverse ? node.instructions.getLast() : node.instructions.getFirst());
74+
public InsnList find(MethodNode node) {
75+
return this.find(this.reverse ? node.instructions.getLast() : node.instructions.getFirst());
7676
}
7777

7878
/**
7979
* Tries to match the given pattern starting from a given node.
8080
* @param node the node to start the search on
81-
* @return the {@link InsnSequence} object representing the matched pattern
81+
* @return the {@link InsnList} object representing the matched pattern
8282
*/
8383
public InsnSequence find(AbstractInsnNode node) {
8484
if(node != null) {
@@ -285,6 +285,11 @@ private static boolean matchList(
285285
return true;
286286
}
287287

288+
private static final BiPredicate<Object, Object> COMPARE_LABELS = (p, ex) -> {
289+
LabelNode expected = (LabelNode) ex;
290+
return expected.equals(p) || expected.getLabel().equals(p);
291+
};
292+
288293
/**
289294
* Tests whether a given {@link AbstractInsnNode} matches the given opcode and arguments.
290295
* @param i the node to test
@@ -382,16 +387,12 @@ && matchList(1, args, lookup.keys.toArray(), false, Object::equals)
382387
case AbstractInsnNode.TABLESWITCH_INSN:
383388
if(args.length < 4) return false;
384389
TableSwitchInsnNode tab = (TableSwitchInsnNode) i;
385-
BiPredicate<Object, Object> compareLabels = (p, ex) -> {
386-
LabelNode expected = (LabelNode) ex;
387-
return expected.equals(p) || expected.getLabel().equals(p);
388-
};
389390
return args[0] instanceof Integer
390391
&& tab.min == (Integer) args[0]
391392
&& args[1] instanceof Integer
392393
&& tab.min == (Integer) args[1]
393-
&& compareLabels.test(args[2], tab.dflt)
394-
&& matchList(3, args, tab.labels.toArray(), true, compareLabels);
394+
&& COMPARE_LABELS.test(args[2], tab.dflt)
395+
&& matchList(3, args, tab.labels.toArray(), true, COMPARE_LABELS);
395396
case AbstractInsnNode.VAR_INSN:
396397
return args.length == 1
397398
&& ((VarInsnNode) i).var == (Integer) args[0];

0 commit comments

Comments
 (0)