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: e91a966897ad
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c4e1dfe8b48d
Choose a head ref
  • 5 commits
  • 1 file changed
  • 1 contributor

Commits on Jul 8, 2017

  1. Copy the full SHA
    d2d2e41 View commit details
  2. Copy the full SHA
    3880a04 View commit details
  3. Copy the full SHA
    2ad5364 View commit details
  4. Fix ClassCastException for rationals that get reduced.

    Two fixes here:
    
    * Don't use the reducing forms of Rational construction, since
      they may not return a Rational and we expect one here.
    * Don't expect that our Rational stays a Rational because the
      mathn library can change that behavior.
    
    For more info about the second fix, see ruby/ruby@78729a59.
    headius committed Jul 8, 2017
    Copy the full SHA
    92adf23 View commit details
  5. Copy the full SHA
    c4e1dfe View commit details
Showing with 36 additions and 18 deletions.
  1. +36 −18 core/src/main/java/org/jruby/RubyArray.java
54 changes: 36 additions & 18 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -1577,12 +1577,17 @@ public RubyArray concat(ThreadContext context, IRubyObject obj) {

RubyArray ary = obj.convertToArray();

if (ary.realLength > 0) splice(realLength, 0, ary, false);
return aryAppend(ary);
}

// MRI: ary_append
public RubyArray aryAppend(RubyArray y) {
if (y.realLength > 0) splice(realLength, 0, y, false);

return this;
}

/** rb_ary_concat
/** rb_ary_concat_multi
*
*/
@JRubyMethod(name = "concat", rest = true)
@@ -1598,7 +1603,7 @@ public RubyArray concat(ThreadContext context, IRubyObject[] objs) {
tmp.concat(context, obj);
}

append(tmp);
aryAppend(tmp);
}

return this;
@@ -3097,7 +3102,7 @@ public IRubyObject flatten_bang(ThreadContext context) {
unpack();
modifyCheck();

RubyArray result = new RubyArray(context.runtime, getMetaClass(), realLength);
RubyArray result = new RubyArray(context.runtime, getType(), realLength);
if (flatten(context, -1, result)) {
modifyCheck();
isShared = false;
@@ -3117,7 +3122,7 @@ public IRubyObject flatten_bang(ThreadContext context, IRubyObject arg) {
int level = RubyNumeric.num2int(arg);
if (level == 0) return context.nil;

RubyArray result = new RubyArray(context.runtime, getMetaClass(), realLength);
RubyArray result = new RubyArray(context.runtime, getType(), realLength);
if (flatten(context, level, result)) {
isShared = false;
begin = 0;
@@ -3137,7 +3142,7 @@ public IRubyObject flatten_bang19(ThreadContext context, IRubyObject arg) {
public IRubyObject flatten(ThreadContext context) {
Ruby runtime = context.runtime;

RubyArray result = new RubyArray(runtime, getMetaClass(), realLength);
RubyArray result = new RubyArray(runtime, getType(), realLength);
flatten(context, -1, result);
result.infectBy(this);
return result;
@@ -3149,7 +3154,7 @@ public IRubyObject flatten(ThreadContext context, IRubyObject arg) {
int level = RubyNumeric.num2int(arg);
if (level == 0) return makeShared();

RubyArray result = new RubyArray(runtime, getMetaClass(), realLength);
RubyArray result = new RubyArray(runtime, getType(), realLength);
flatten(context, level, result);
result.infectBy(this);
return result;
@@ -3851,20 +3856,19 @@ public IRubyObject repeatedCombination(ThreadContext context, IRubyObject num, B
if (!block.isGiven()) return enumeratorizeWithSize(context, this, "repeated_combination", new IRubyObject[] { num }, repeatedCombinationSize(context));

int n = RubyNumeric.num2int(num);
int len = realLength;

if (n < 0) {
// yield nothing
} else if (n == 0) {
block.yield(context, newEmptyArray(runtime));
} else if (n == 1) {
for (int i = 0; i < len; i++) {
for (int i = 0; i < realLength; i++) {
block.yield(context, newArray(runtime, eltOk(i)));
}
} else {
int[] p = new int[n];
RubyArray values = makeShared();
rcombinate(context, len, n, p, values, block);
rcombinate(context, realLength, n, p, values, block);
}

return this;
@@ -4399,7 +4403,7 @@ public IRubyObject sumCommon(final ThreadContext context, IRubyObject init, fina
if (is_bignum) {
result = RubyBignum.newBignum(runtime, sum);
} else if (is_rational) {
result = RubyRational.newRationalCanonicalize(context, sum, 1);
result = RubyRational.newRational(runtime, sum, 1);
} else if (is_float) {
result = RubyFloat.newFloat(runtime, (double) sum);
} else {
@@ -4436,7 +4440,7 @@ public IRubyObject sumCommon(final ThreadContext context, IRubyObject init, fina
}

if (is_rational) {
result = RubyRational.newRationalCanonicalize(context, RubyBignum.newBignum(runtime, sum), RubyFixnum.one(runtime));
result = RubyRational.newRationalConvert(context, RubyBignum.newBignum(runtime, sum), RubyFixnum.one(runtime));
} else if (is_float) {
result = RubyFloat.newFloat(runtime, sum.doubleValue());
} else {
@@ -4454,7 +4458,13 @@ public IRubyObject sumCommon(final ThreadContext context, IRubyObject init, fina
}

if (value instanceof RubyFixnum || value instanceof RubyBignum || value instanceof RubyRational) {
result = ((RubyRational) result).op_add(context, value);
if (result instanceof RubyInteger) {
result = ((RubyInteger) result).op_plus(context, value);
} else if (result instanceof RubyRational) {
result = ((RubyRational) result).op_add(context, value);
} else {
throw runtime.newTypeError("BUG: unexpected type in rational part of Array#sum");
}
} else if (value instanceof RubyFloat) {
result = RubyFloat.newFloat(runtime, ((RubyRational) result).getDoubleValue(context));
is_float = true;
@@ -4465,9 +4475,13 @@ public IRubyObject sumCommon(final ThreadContext context, IRubyObject init, fina
}
}
if (is_float) {
/*
* Kahan-Babuska balancing compensated summation algorithm
* See http://link.springer.com/article/10.1007/s00607-005-0139-x
*/
double f = ((RubyFloat) result).getDoubleValue();
double c = 0.0;
double x, y, t;
double x, t;
float_loop:
for (; i < realLength; value=null, i++) {
if (value == null) {
@@ -4488,12 +4502,16 @@ public IRubyObject sumCommon(final ThreadContext context, IRubyObject init, fina
} else {
break float_loop;
}
// Kahan's compensated summation algorithm
y = x - c;
t = f + y;
c = (t - f) - y;
t = f + x;
if (Math.abs(f) >= Math.abs(x)) {
c += ((f - t) + x);
} else {
c += ((x - t) + f);
}
f = t;
}
f += c;

result = new RubyFloat(runtime, f);
}
//object_loop: