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: 3ee92172576b
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 925310c49a03
Choose a head ref
  • 11 commits
  • 12 files changed
  • 1 contributor

Commits on Aug 1, 2016

  1. Copy the full SHA
    ae3c56f View commit details
  2. Copy the full SHA
    d7fa2ea View commit details
  3. Copy the full SHA
    d478130 View commit details
  4. Copy the full SHA
    ecd5adb View commit details
  5. [ji] handle #count() as #size for java.util.Collection types

    ... there's smt messy going on when count re-defs are added
    rspec (once again) turns out a very poor choice for JI testing
    kares committed Aug 1, 2016
    Copy the full SHA
    37735b8 View commit details
  6. Copy the full SHA
    ddf7fa1 View commit details
  7. Copy the full SHA
    f746e16 View commit details
  8. Copy the full SHA
    e7ce679 View commit details
  9. Copy the full SHA
    1657726 View commit details
  10. RubyArray's newArrayMayCopy does not need to actually copy array

    + use newArrayNoCopy when the size is known to be large
    kares committed Aug 1, 2016
    Copy the full SHA
    1cb58ef View commit details
  11. Copy the full SHA
    925310c View commit details
12 changes: 4 additions & 8 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -265,10 +265,7 @@ public static RubyArray newArrayMayCopy(Ruby runtime, IRubyObject... args) {
case 2:
return new RubyArrayTwoObject(runtime, args[0], args[1]);
}
RubyArray arr = new RubyArray(runtime, new IRubyObject[args.length]);
System.arraycopy(args, 0, arr.values, 0, args.length);
arr.realLength = args.length;
return arr;
return newArrayNoCopy(runtime, args, 0, args.length);
}

/**
@@ -4032,7 +4029,7 @@ public IRubyObject shuffle(ThreadContext context, IRubyObject[] args) {
return ary;
}

private static int SORTED_THRESHOLD = 10;
private static final int SORTED_THRESHOLD = 10;

@JRubyMethod(name = "sample", optional = 2)
public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
@@ -4107,8 +4104,7 @@ public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
}
if (k >= l && (++k >= g))
++k;
return newArray(runtime, eltOk(i),
eltOk(j), eltOk(k));
return newArray(runtime, eltOk(i), eltOk(j), eltOk(k));
}

int len = realLength;
@@ -4141,7 +4137,7 @@ public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
result[j] = result[i];
result[i] = tmp;
}
RubyArray ary = newArrayMayCopy(runtime, result);
RubyArray ary = newArrayNoCopy(runtime, result);
ary.realLength = n;
return ary;
}
133 changes: 96 additions & 37 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -143,6 +143,7 @@ private static void checkContext(ThreadContext firstContext, ThreadContext secon
}
}

@Deprecated
public static IRubyObject count18(ThreadContext context, IRubyObject self, final Block block) {
return count(context, self, block);
}
@@ -309,8 +310,13 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
return result;
}

@JRubyMethod(name = "take_while")
@Deprecated
public static IRubyObject take_while19(ThreadContext context, IRubyObject self, final Block block) {
return take_while(context, self, block);
}

@JRubyMethod(name = "take_while")
public static IRubyObject take_while(ThreadContext context, IRubyObject self, final Block block) {
if (!block.isGiven()) {
return enumeratorize(context.runtime, self, "take_while");
}
@@ -434,25 +440,27 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
return result;
}

@JRubyMethod(name = {"to_a", "entries"})
public static IRubyObject to_a(ThreadContext context, IRubyObject self) {
return to_a19(context, self);
@Deprecated
public static IRubyObject to_a19(ThreadContext context, IRubyObject self) {
return to_a(context, self);
}

@JRubyMethod(name = {"to_a", "entries"}, rest = true)
public static IRubyObject to_a(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return to_a19(context, self, args);
@Deprecated
public static IRubyObject to_a19(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return to_a(context, self, args);
}

public static IRubyObject to_a19(ThreadContext context, IRubyObject self) {
@JRubyMethod(name = {"to_a", "entries"})
public static IRubyObject to_a(ThreadContext context, IRubyObject self) {
Ruby runtime = context.runtime;
RubyArray result = runtime.newArray();
callEach(runtime, context, self, Signature.OPTIONAL, new AppendBlockCallback(result));
result.infectBy(self);
return result;
}

public static IRubyObject to_a19(ThreadContext context, IRubyObject self, IRubyObject[] args) {
@JRubyMethod(name = {"to_a", "entries"}, rest = true)
public static IRubyObject to_a(ThreadContext context, IRubyObject self, IRubyObject[] args) {
final Ruby runtime = context.runtime;
final RubyArray result = runtime.newArray();
Helpers.invoke(context, self, "each", args, CallBlock.newCallClosure(self, runtime.getEnumerable(),
@@ -647,11 +655,12 @@ public static IRubyObject find(ThreadContext context, IRubyObject self, IRubyObj
enumeratorize(context.runtime, self, "find", ifnone);
}

@JRubyMethod(name = "find_index")
@Deprecated
public static IRubyObject find_index19(ThreadContext context, IRubyObject self, final Block block) {
return find_index(context, self, block);
}

@JRubyMethod(name = "find_index")
public static IRubyObject find_index(ThreadContext context, IRubyObject self, final Block block) {
boolean blockGiven = block.isGiven();

@@ -661,7 +670,7 @@ public static IRubyObject find_index(ThreadContext context, IRubyObject self, fi
enumeratorize(context.runtime, self, "find_index");
}

@Deprecated
@Deprecated @SuppressWarnings("deprecation")
public static IRubyObject find_index(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
boolean blockGiven = block.isGiven();

@@ -671,11 +680,12 @@ public static IRubyObject find_index(ThreadContext context, IRubyObject self, fi
enumeratorize(context.runtime, self, "find_index");
}

@JRubyMethod(name = "find_index")
@Deprecated
public static IRubyObject find_index19(ThreadContext context, IRubyObject self, final IRubyObject cond, final Block block) {
return find_index(context, self, cond, block);
}

@JRubyMethod(name = "find_index")
public static IRubyObject find_index(ThreadContext context, IRubyObject self, final IRubyObject cond, final Block block) {
final Ruby runtime = context.runtime;

@@ -800,17 +810,27 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return result;
}

@JRubyMethod(name = {"collect"})
@Deprecated
public static IRubyObject collect19(ThreadContext context, IRubyObject self, final Block block) {
return collectCommon19(context, self, block, "collect");
return collect(context, self, block);
}

@JRubyMethod(name = {"map"})
@Deprecated
public static IRubyObject map19(ThreadContext context, IRubyObject self, final Block block) {
return collectCommon19(context, self, block, "map");
return map(context, self, block);
}

@JRubyMethod(name = "collect")
public static IRubyObject collect(ThreadContext context, IRubyObject self, final Block block) {
return collectCommon(context, self, block, "collect");
}

@JRubyMethod(name = "map")
public static IRubyObject map(ThreadContext context, IRubyObject self, final Block block) {
return collectCommon(context, self, block, "map");
}

private static IRubyObject collectCommon19(ThreadContext context, IRubyObject self, final Block block, String methodName) {
private static IRubyObject collectCommon(ThreadContext context, IRubyObject self, final Block block, String methodName) {
final Ruby runtime = context.runtime;
if (block.isGiven()) {
final RubyArray result = runtime.newArray();
@@ -835,23 +855,34 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
}
}

@Deprecated
public static IRubyObject collectCommon(ThreadContext context, Ruby runtime, IRubyObject self,
RubyArray result, final Block block, BlockCallback blockCallback) {
callEach(runtime, context, self, Signature.ONE_ARGUMENT, blockCallback);
return result;
}

@JRubyMethod(name = {"flat_map"})
@Deprecated
public static IRubyObject flat_map19(ThreadContext context, IRubyObject self, final Block block) {
return flatMapCommon19(context, self, block, "flat_map");
return flat_map(context, self, block);
}

@JRubyMethod(name = {"collect_concat"})
@Deprecated
public static IRubyObject collect_concat19(ThreadContext context, IRubyObject self, final Block block) {
return flatMapCommon19(context, self, block, "collect_concat");
return collect_concat(context, self, block);
}

@JRubyMethod(name = "flat_map")
public static IRubyObject flat_map(ThreadContext context, IRubyObject self, final Block block) {
return flatMapCommon(context, self, block, "flat_map");
}

@JRubyMethod(name = "collect_concat")
public static IRubyObject collect_concat(ThreadContext context, IRubyObject self, final Block block) {
return flatMapCommon(context, self, block, "collect_concat");
}

private static IRubyObject flatMapCommon19(ThreadContext context, IRubyObject self, final Block block, String methodName) {
private static IRubyObject flatMapCommon(ThreadContext context, IRubyObject self, final Block block, String methodName) {
final Ruby runtime = context.runtime;
if (block.isGiven()) {
final RubyArray ary = runtime.newArray();
@@ -1002,12 +1033,22 @@ public static IRubyObject each_with_indexCommon(ThreadContext context, IRubyObje
return self;
}

public static IRubyObject each_with_indexCommon19(ThreadContext context, IRubyObject self, Block block, IRubyObject[] args) {
public static IRubyObject each_with_indexCommon(ThreadContext context, IRubyObject self, Block block, IRubyObject[] args) {
callEach(context.runtime, context, self, args, Signature.OPTIONAL, new EachWithIndex(block));
return self;
}

@Deprecated
public static IRubyObject each_with_indexCommon19(ThreadContext context, IRubyObject self, Block block, IRubyObject[] args) {
return each_with_indexCommon(context, self, block, args);
}

@Deprecated
public static IRubyObject each_with_objectCommon19(ThreadContext context, IRubyObject self, final Block block, final IRubyObject arg) {
return each_with_objectCommon(context, self, block, arg);
}

public static IRubyObject each_with_objectCommon(ThreadContext context, IRubyObject self, final Block block, final IRubyObject arg) {
final Ruby runtime = context.runtime;
RubyEnumerable.callEach(runtime, context, self, Signature.OPTIONAL, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
@@ -1018,17 +1059,22 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
}

public static IRubyObject each_with_index(ThreadContext context, IRubyObject self, Block block) {
return each_with_index19(context, self, IRubyObject.NULL_ARRAY, block);
return each_with_index(context, self, IRubyObject.NULL_ARRAY, block);
}

@JRubyMethod(name = "each_with_index", rest = true)
public static IRubyObject each_with_index(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
return block.isGiven() ? each_with_indexCommon(context, self, block, args) : enumeratorizeWithSize(context, self, "each_with_index", args, enumSizeFn(context, self));
}

@Deprecated @SuppressWarnings("deprecation")
public static IRubyObject each_with_index19(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
return block.isGiven() ? each_with_indexCommon19(context, self, block, args) : enumeratorizeWithSize(context, self, "each_with_index", args, enumSizeFn(context, self));
return each_with_index19(context, self, args, block);
}

@JRubyMethod(required = 1)
public static IRubyObject each_with_object(ThreadContext context, IRubyObject self, IRubyObject arg, Block block) {
return block.isGiven() ? each_with_objectCommon19(context, self, block, arg) : enumeratorizeWithSize(context, self, "each_with_object", new IRubyObject[] { arg }, enumSizeFn(context, self));
return block.isGiven() ? each_with_objectCommon(context, self, block, arg) : enumeratorizeWithSize(context, self, "each_with_object", new IRubyObject[] { arg }, enumSizeFn(context, self));
}

@JRubyMethod(rest = true)
@@ -1045,7 +1091,18 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return self;
}

@Deprecated
public static IRubyObject each_slice19(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
return each_slice(context, self, arg, block);
}

@JRubyMethod(name = "each_slice")
public static IRubyObject each_slice(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
return block.isGiven() ? each_sliceCommon(context, self, arg, block) :
enumeratorizeWithSize(context, self, "each_slice", new IRubyObject[]{arg}, eachSliceSizeFn(context, self));
}

static IRubyObject each_sliceCommon(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
final int size = RubyNumeric.num2int(arg);
final Ruby runtime = context.runtime;
if (size <= 0) throw runtime.newArgumentError("invalid slice size");
@@ -1067,11 +1124,6 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return context.nil;
}

@JRubyMethod(name = "each_slice")
public static IRubyObject each_slice19(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
return block.isGiven() ? each_slice(context, self, arg, block) : enumeratorizeWithSize(context, self, "each_slice", new IRubyObject[]{arg}, eachSliceSizeFn(context, self));
}

private static SizeFn eachSliceSizeFn(final ThreadContext context, final IRubyObject self) {
return new SizeFn() {
@Override
@@ -1094,8 +1146,18 @@ public IRubyObject size(IRubyObject[] args) {
};
}

@Deprecated
public static IRubyObject each_cons19(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
return each_cons(context, self, arg, block);
}

@JRubyMethod(name = "each_cons")
public static IRubyObject each_cons(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
final int size = (int)RubyNumeric.num2long(arg);
return block.isGiven() ? each_consCommon(context, self, arg, block) : enumeratorizeWithSize(context, self, "each_cons", new IRubyObject[] { arg }, eachConsSizeFn(context, self));
}

static IRubyObject each_consCommon(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
final int size = (int) RubyNumeric.num2long(arg);
final Ruby runtime = context.runtime;
if (size <= 0) throw runtime.newArgumentError("invalid size");

@@ -1113,11 +1175,6 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return context.nil;
}

@JRubyMethod(name = "each_cons")
public static IRubyObject each_cons19(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
return block.isGiven() ? each_cons(context, self, arg, block) : enumeratorizeWithSize(context, self, "each_cons", new IRubyObject[] { arg }, eachConsSizeFn(context, self));
}

private static SizeFn eachConsSizeFn(final ThreadContext context, final IRubyObject self) {
return new SizeFn() {
@Override
@@ -1477,6 +1534,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return result[0] ? runtime.getTrue() : runtime.getFalse();
}

@Deprecated
public static IRubyObject one_p19(ThreadContext context, IRubyObject self, final Block block) {
return one_p(context, self, block);
}
@@ -1530,6 +1588,7 @@ public static IRubyObject all_p(ThreadContext context, IRubyObject self, final B
return all_pCommon(context, self, block);
}

@Deprecated
public static IRubyObject all_p19(ThreadContext context, IRubyObject self, final Block block) {
return all_p(context, self, block);
}
Loading