Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f416bf988ddf
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8dfbf420882f
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Aug 9, 2017

  1. Copy the full SHA
    580c79e View commit details
  2. Copy the full SHA
    648dbce View commit details
  3. Copy the full SHA
    8dfbf42 View commit details
12 changes: 8 additions & 4 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -1192,9 +1192,11 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject other) {
*/
@Override
public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
if (!(other instanceof RubyFixnum)) return RubyBignum.newBignum(context.runtime, value).op_lshift(other);
if (!(other instanceof RubyFixnum)) {
return RubyBignum.newBignum(context.runtime, value).op_lshift(context, other);
}

return op_lshift(((RubyFixnum)other).getLongValue());
return op_lshift(((RubyFixnum) other).getLongValue());
}

public IRubyObject op_lshift(long width) {
@@ -1213,9 +1215,11 @@ private IRubyObject lshift(long width) {
*/
@Override
public IRubyObject op_rshift(ThreadContext context, IRubyObject other) {
if (!(other instanceof RubyFixnum)) return RubyBignum.newBignum(context.runtime, value).op_rshift(other);
if (!(other instanceof RubyFixnum)) {
return RubyBignum.newBignum(context.runtime, value).op_rshift(context, other);
}

return op_rshift(((RubyFixnum)other).getLongValue());
return op_rshift(((RubyFixnum) other).getLongValue());
}

public IRubyObject op_rshift(long width) {
10 changes: 7 additions & 3 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.ObjectAllocator;
@@ -643,12 +644,11 @@ static IRubyObject intValue(ThreadContext context, IRubyObject num) {

static IRubyObject toInteger(ThreadContext context, IRubyObject num) {
if (num instanceof RubyInteger) return num;
if (num instanceof RubyNumeric && !num.callMethod(context, "integer?").isTrue()) {
if (num instanceof RubyNumeric && !integer_p(context).call(context, num, num).isTrue()) { // num.integer?
return null;
}
if (num instanceof RubyString) return null; // do not want String#to_i
if (num.respondsTo("to_i")) return num.callMethod(context, "to_i");
return null;
return num.checkCallMethod(context, sites(context).to_i_checked);
}

@JRubyMethod(name = "digits")
@@ -802,6 +802,10 @@ public IRubyObject size() {
return size(getRuntime().getCurrentContext());
}

private static CallSite integer_p(ThreadContext context) {
return context.sites.Numeric.integer;
}

private static JavaSites.IntegerSites sites(ThreadContext context) {
return context.sites.Integer;
}
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -848,7 +848,7 @@ public IRubyObject ceil(ThreadContext context, IRubyObject n) {

// MRI: nurat_ceil
private IRubyObject mriCeil(ThreadContext context) {
return ((RubyInteger) ((RubyInteger) num.op_uminus()).idiv(context, den)).op_uminus();
return ((RubyInteger) ((RubyInteger) num.op_uminus(context)).idiv(context, den)).op_uminus(context);
}

@JRubyMethod(name = "to_i")
@@ -871,7 +871,7 @@ public IRubyObject truncate(ThreadContext context, IRubyObject n) {

private IRubyObject mriTruncate(ThreadContext context) {
if (num.isNegative(context).isTrue()) {
return ((RubyInteger) ((RubyInteger) num.op_uminus()).idiv(context, den)).op_uminus();
return ((RubyInteger) ((RubyInteger) num.op_uminus(context)).idiv(context, den)).op_uminus(context);
}
return num.idiv(context, den);
}
@@ -979,7 +979,7 @@ private RubyInteger roundHalfDown(ThreadContext context) {
neg = num.isNegative(context);

if (neg.isTrue()) {
num = (RubyInteger) num.op_uminus();
num = (RubyInteger) num.op_uminus(context);
}

num = (RubyInteger) ((RubyInteger) num.op_mul(context, RubyFixnum.two(runtime))).op_plus(context, den);
@@ -988,7 +988,7 @@ private RubyInteger roundHalfDown(ThreadContext context) {
num = (RubyInteger) num.idiv(context, den);

if (neg.isTrue())
num = (RubyInteger) num.op_uminus();
num = (RubyInteger) num.op_uminus(context);

return num;
}
@@ -1032,15 +1032,15 @@ private RubyInteger roundHalfUp(ThreadContext context) {
neg = num.isNegative(context);

if (neg.isTrue()) {
num = (RubyInteger) num.op_uminus();
num = (RubyInteger) num.op_uminus(context);
}

num = (RubyInteger) ((RubyInteger) num.op_mul(context, RubyFixnum.two(runtime))).op_plus(context, den);
den = (RubyInteger) den.op_mul(context, RubyFixnum.two(runtime));
num = (RubyInteger) num.idiv(context, den);

if (neg.isTrue()) {
num = (RubyInteger) num.op_uminus();
num = (RubyInteger) num.op_uminus(context);
}

return num;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -207,6 +207,7 @@ public static class IntegerSites {
public final CallSite op_quo = new FunctionalCachingCallSite("/");
public final CallSite op_mod = new FunctionalCachingCallSite("%");
public final CallSite size = new FunctionalCachingCallSite("size");
public final CheckedSites to_i_checked = new CheckedSites("to_i");
}

public static class FixnumSites {
@@ -395,7 +396,6 @@ public static class RangeSites {
}

public static class WarningSites {
public final CheckedSites to_int_checked = new CheckedSites("to_str");
public final CallSite warn = new FunctionalCachingCallSite("warn");
public final CallSite write = new FunctionalCachingCallSite("write");
}
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s
@Override
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg) {
if (self instanceof RubyFixnum && !context.runtime.isFixnumReopened()) {
return ((RubyFixnum) self).op_lshift(arg);
return ((RubyFixnum) self).op_lshift(context, arg);
}
return super.call(context, caller, self, arg);
}
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s
@Override
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg) {
if (self instanceof RubyFixnum && !context.runtime.isFixnumReopened()) {
return ((RubyFixnum) self).op_rshift(arg);
return ((RubyFixnum) self).op_rshift(context, arg);
}
return super.call(context, caller, self, arg);
}