Skip to content

Commit

Permalink
[Truffle] Lazily create the dispatch node for adding Rationals to Fix…
Browse files Browse the repository at this point in the history
…nums.
  • Loading branch information
nirvdrum committed Jan 8, 2015
1 parent 2e2d97d commit e941b67
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
Expand Up @@ -71,12 +71,10 @@ public abstract static class AddNode extends BignumNodes.BignumCoreMethodNode {

public AddNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
rationalAdd = new DispatchHeadNode(context);
}

public AddNode(AddNode prev) {
super(prev);
rationalAdd = prev.rationalAdd;
}

@Specialization(rewriteOn = ArithmeticException.class)
Expand Down Expand Up @@ -111,6 +109,12 @@ public Object add(int a, RubyBignum b) {

@Specialization(guards = "isRational(arguments[1])")
public Object add(VirtualFrame frame, int a, RubyBasicObject b) {
if (rationalAdd == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();

rationalAdd = insert(new DispatchHeadNode(getContext()));
}

return rationalAdd.call(frame, b, "+", null, a);
}

Expand Down Expand Up @@ -146,6 +150,12 @@ public Object add(long a, RubyBignum b) {

@Specialization(guards = "isRational(arguments[1])")
public Object add(VirtualFrame frame, long a, RubyBasicObject b) {
if (rationalAdd == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();

rationalAdd = insert(new DispatchHeadNode(getContext()));
}

return rationalAdd.call(frame, b, "+", null, a);
}

Expand Down

0 comments on commit e941b67

Please sign in to comment.