Skip to content

Commit

Permalink
Minor perf improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Oct 28, 2023
1 parent 880e811 commit 2a350e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ public List<Instruction<?>> 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<ASTIdentifier> localParams = parameters;
for (int i = 0; i < localParams.size(); i++) {
visitor.visitParameter(i, localParams.get(i));
}
if(this.code == null) {
visitor.visitEnd();
Expand All @@ -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<ASTInstruction> localAstInstructions = code.instructions();
List<Instruction<?>> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public Transformer(ASTRootVisitor visitor) {
*/
public Result<Void> transform(List<ASTElement> 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());
}
Expand Down

0 comments on commit 2a350e6

Please sign in to comment.