diff --git a/jasm-core/src/main/java/me/darknet/assembler/ast/specific/ASTMethod.java b/jasm-core/src/main/java/me/darknet/assembler/ast/specific/ASTMethod.java index 3c3e019..119a618 100644 --- a/jasm-core/src/main/java/me/darknet/assembler/ast/specific/ASTMethod.java +++ b/jasm-core/src/main/java/me/darknet/assembler/ast/specific/ASTMethod.java @@ -54,10 +54,12 @@ public List> instructions() { return instructions; } + @SuppressWarnings("UnnecessaryLocalVariable") public void accept(ErrorCollector collector, ASTMethodVisitor visitor) { super.accept(collector, visitor); - for (int i = 0; i < parameters.size(); i++) { - visitor.visitParameter(i, parameters.get(i)); + List localParams = parameters; + for (int i = 0; i < localParams.size(); i++) { + visitor.visitParameter(i, localParams.get(i)); } if(this.code == null) { visitor.visitEnd(); @@ -69,13 +71,14 @@ public void accept(ErrorCollector collector, ASTMethodVisitor visitor) { }; if (instructionVisitor != null) { int instructionIndex = 0; - for (int i = 0; i < code.instructions().size(); i++) { - ASTInstruction instruction = code.instructions().get(i); - if(instruction instanceof ASTLabel lab) { + List localAstInstructions = code.instructions(); + List> localIrInstructions = instructions; + for (ASTInstruction instruction : localAstInstructions) { + if (instruction instanceof ASTLabel lab) { instructionVisitor.visitLabel(lab.identifier()); } else { instructionVisitor.visitInstruction(instruction); - instructions.get(instructionIndex++).transform(instruction, instructionVisitor); + localIrInstructions.get(instructionIndex++).transform(instruction, instructionVisitor); } } diff --git a/jasm-core/src/main/java/me/darknet/assembler/transformer/Transformer.java b/jasm-core/src/main/java/me/darknet/assembler/transformer/Transformer.java index f97ecbc..7791186 100644 --- a/jasm-core/src/main/java/me/darknet/assembler/transformer/Transformer.java +++ b/jasm-core/src/main/java/me/darknet/assembler/transformer/Transformer.java @@ -29,13 +29,14 @@ public Transformer(ASTRootVisitor visitor) { */ public Result transform(List declarations) { ErrorCollector collector = new ErrorCollector(); + ASTRootVisitor localVisitor = visitor; for (ASTElement declaration : declarations) { if (declaration instanceof ASTField field) { - field.accept(collector, visitor.visitField(field.modifiers(), field.name(), field.descriptor())); + field.accept(collector, localVisitor.visitField(field.modifiers(), field.name(), field.descriptor())); } else if (declaration instanceof ASTMethod method) { - method.accept(collector, visitor.visitMethod(method.modifiers(), method.name(), method.descriptor())); + method.accept(collector, localVisitor.visitMethod(method.modifiers(), method.name(), method.descriptor())); } else if (declaration instanceof ASTClass clazz) { - clazz.accept(collector, visitor.visitClass(clazz.modifiers(), clazz.name())); + clazz.accept(collector, localVisitor.visitClass(clazz.modifiers(), clazz.name())); } else { collector.addError("Don't know how to process: " + declaration.type(), declaration.location()); }