Skip to content

Commit

Permalink
[Truffle] Adding Rational long specialization for Fixnum#-.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Apr 7, 2015
1 parent bd21747 commit 73bbd14
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -248,6 +248,19 @@ public Object sub(VirtualFrame frame, int a, RubyBasicObject b) {
return rationalSubNode.call(frame, aRational, "-", null, b);
}

@Specialization(guards = "isRational(arguments[1])")
public Object sub(VirtualFrame frame, long a, RubyBasicObject b) {
if (rationalConvertNode == null) {
CompilerDirectives.transferToInterpreter();
rationalConvertNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext(), true));
rationalSubNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object aRational = rationalConvertNode.call(frame, getContext().getCoreLibrary().getRationalClass(), "convert", null, a, 1);

return rationalSubNode.call(frame, aRational, "-", null, b);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long sub(long a, int b) {
return ExactMath.subtractExact(a, b);
Expand Down

0 comments on commit 73bbd14

Please sign in to comment.