Skip to content

Commit 8fbe84a

Browse files
committed
Make boolean constructor private and kill off leak of new Boolean in IRBuilder
1 parent 0e46662 commit 8fbe84a

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

core/src/main/java/org/jruby/ir/IRBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3200,7 +3200,7 @@ public Operand buildReturn(ReturnNode returnNode, IRScope s) {
32003200
// If this happens to be a module body, the runtime throws a local jump error if the
32013201
// closure is a proc. If the closure is a lambda, then this becomes a normal return.
32023202
IRMethod m = s.getNearestMethod();
3203-
addInstr(s, new RuntimeHelperCall(null, CHECK_FOR_LJE, new Operand[] { new Boolean(m == null) }));
3203+
addInstr(s, new RuntimeHelperCall(null, CHECK_FOR_LJE, new Operand[] { m == null ? Boolean.TRUE : Boolean.FALSE }));
32043204
retVal = processEnsureRescueBlocks(s, retVal);
32053205
addInstr(s, new NonlocalReturnInstr(retVal, m == null ? "--none--" : m.getName()));
32063206
} else if (s.isModuleBody()) {

core/src/main/java/org/jruby/ir/IRManager.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import org.jruby.RubyInstanceConfig;
44
import org.jruby.ir.listeners.IRScopeListener;
55
import org.jruby.ir.listeners.InstructionsListener;
6-
import org.jruby.ir.operands.Nil;
7-
import org.jruby.ir.operands.TemporaryLocalVariable;
6+
import org.jruby.ir.operands.*;
7+
import org.jruby.ir.operands.Boolean;
88
import org.jruby.ir.passes.BasicCompilerPassListener;
99
import org.jruby.ir.passes.CompilerPass;
1010
import org.jruby.ir.passes.CompilerPassListener;
@@ -24,8 +24,7 @@ public class IRManager {
2424
private int dummyMetaClassCount = 0;
2525
private final IRModuleBody object = new IRClassBody(this, null, "Object", "", 0, null);
2626
private final Nil nil = new Nil();
27-
private final org.jruby.ir.operands.Boolean trueObject = new org.jruby.ir.operands.Boolean(true);
28-
private final org.jruby.ir.operands.Boolean falseObject = new org.jruby.ir.operands.Boolean(false);
27+
2928
// Listeners for debugging and testing of IR
3029
private Set<CompilerPassListener> passListeners = new HashSet<CompilerPassListener>();
3130
private CompilerPassListener defaultListener = new BasicCompilerPassListener();
@@ -63,11 +62,11 @@ public Nil getNil() {
6362
}
6463

6564
public org.jruby.ir.operands.Boolean getTrue() {
66-
return trueObject;
65+
return Boolean.TRUE;
6766
}
6867

6968
public org.jruby.ir.operands.Boolean getFalse() {
70-
return falseObject;
69+
return Boolean.FALSE;
7170
}
7271

7372
public IRModuleBody getObject() {

core/src/main/java/org/jruby/ir/operands/Boolean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Boolean extends ImmutableLiteral {
99
public static final Boolean TRUE = new Boolean(true);
1010
public static final Boolean FALSE = new Boolean(false);
1111

12-
public Boolean(boolean truthy) {
12+
private Boolean(boolean truthy) {
1313
super(OperandType.BOOLEAN);
1414

1515
this.truthy = truthy;

0 commit comments

Comments
 (0)