Skip to content

Commit

Permalink
Reuse temp variables in InCodeGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
pettyjamesm committed May 17, 2024
1 parent 9929105 commit 34b8303
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext
LabelNode defaultLabel = new LabelNode("default");

Scope scope = generatorContext.getScope();
Variable value = scope.createTempVariable(javaType);
Variable value = scope.getOrCreateTempVariable(javaType);

BytecodeNode switchBlock;
Variable expression = scope.createTempVariable(int.class);
Variable expression = scope.getOrCreateTempVariable(int.class);
SwitchBuilder switchBuilder = new SwitchBuilder().expression(expression);

switch (switchGenerationCase) {
Expand Down Expand Up @@ -278,6 +278,9 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext

block.visitLabel(end);

scope.releaseTempVariableForReuse(expression);
scope.releaseTempVariableForReuse(value);

return block;
}

Expand All @@ -299,7 +302,7 @@ private static BytecodeBlock buildInCase(
{
Variable caseWasNull = null; // caseWasNull is set to true the first time a null in `testValues` is encountered
if (checkForNulls) {
caseWasNull = scope.createTempVariable(boolean.class);
caseWasNull = scope.getOrCreateTempVariable(boolean.class);
}

BytecodeBlock caseBlock = new BytecodeBlock();
Expand Down Expand Up @@ -360,6 +363,10 @@ private static BytecodeBlock buildInCase(
elseLabel = testLabel;
}
caseBlock.append(elseNode);

if (checkForNulls) {
scope.releaseTempVariableForReuse(caseWasNull);
}
return caseBlock;
}

Expand Down

0 comments on commit 34b8303

Please sign in to comment.