Skip to content

Commit

Permalink
Reduce weird if check to a single line with a FIXME explaining why it…
Browse files Browse the repository at this point in the history
… exists in cloneInstrs
  • Loading branch information
enebo committed Feb 19, 2015
1 parent bfd49a8 commit 35ea009
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -648,20 +648,23 @@ protected void cloneInstrs() {
}

protected void cloneInstrs(SimpleCloneInfo cloneInfo) {
if (getCFG() == null) {
List<Instr> newInstrList = new ArrayList<Instr>(this.instrList.size());
for (Instr instr: this.instrList) {
newInstrList.add(instr.clone(cloneInfo));
}
this.instrList = newInstrList;
this.state = ScopeState.INSTRS_CLONED;
for (IRClosure cl : getClosures()) {
cl.cloneInstrs(cloneInfo.cloneForCloningClosure(cl));
}
} else {
for (IRClosure cl : getClosures()) {
cl.cloneInstrs();
}
// FIXME: not cloning if we happen to have a CFG violates the spirit of this method name.
// We do this currently because in a scenario where a nested closure is called much more than
// an outer scope we will process that closure first independently. If at a later point we
// process the outer scope then the inner scope will have nuked instrList and explode if we
// try to clone the non-existent instrList.
if (getCFG() != null) return;

List<Instr> newInstrList = new ArrayList<>(instrList.size());

for (Instr instr: this.instrList) {
newInstrList.add(instr.clone(cloneInfo));
}

instrList = newInstrList;
state = ScopeState.INSTRS_CLONED;
for (IRClosure cl : getClosures()) {
cl.cloneInstrs(cloneInfo.cloneForCloningClosure(cl));
}
}

Expand Down

0 comments on commit 35ea009

Please sign in to comment.