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

Commits on Dec 28, 2015

  1. Copy the full SHA
    282ec21 View commit details
  2. Copy the full SHA
    1d51c91 View commit details
  3. Copy the full SHA
    4c0f942 View commit details
  4. Copy the full SHA
    850709f View commit details
  5. Copy the full SHA
    bfc4393 View commit details
85 changes: 53 additions & 32 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -2383,25 +2383,27 @@ public IRubyObject select_bang(ThreadContext context, Block block) {

modify();

int newLength = 0;
IRubyObject[] aux = new IRubyObject[values.length];
int i1, i2, len0, len1;

for (int oldIndex = 0; oldIndex < realLength; oldIndex++) {
// Do not coarsen the "safe" check, since it will misinterpret
// AIOOBE from the yield (see JRUBY-5434)
IRubyObject value = safeArrayRef(values, begin + oldIndex);
len0 = len1 = 0;

if (!block.yield(context, value).isTrue()) continue;

aux[begin + newLength++] = value;
}

if (realLength == newLength) return runtime.getNil(); // No change
try {
for (i1 = i2 = 0; i1 < size(); len0 = ++i1) {
// Do not coarsen the "safe" check, since it will misinterpret
// AIOOBE from the yield (see JRUBY-5434)
IRubyObject value = safeArrayRef(values, begin + i1);

safeArrayCopy(aux, begin, values, begin, newLength);
realLength = newLength;
if (!block.yield(context, value).isTrue()) continue;

return this;
if (i1 != i2) {
store(i2, value);
}
len1 = ++i2;
}
return (i1 == i2) ? context.nil : this;
} finally {
selectBangEnsure(len0, len1);
}
}

@JRubyMethod
@@ -2517,28 +2519,43 @@ public IRubyObject reject(ThreadContext context, Block block) {
return block.isGiven() ? rejectCommon(context, block) : enumeratorizeWithSize(context, this, "reject", enumLengthFn());
}

/** rb_ary_reject_bang
*
*/
// MRI: ary_reject_bang and reject_bang_i
public IRubyObject rejectBang(ThreadContext context, Block block) {
if (!block.isGiven()) throw context.runtime.newLocalJumpErrorNoBlock();

IRubyObject result = context.runtime.getNil();
modify();

for (int i = 0; i < realLength; /* we adjust i in the loop */) {
// Do not coarsen the "safe" check, since it will misinterpret AIOOBE from the yield
// See JRUBY-5434
IRubyObject v = safeArrayRef(values, begin + i);
if (block.yield(context, v).isTrue()) {
delete_at(i);
result = this;
} else {
i++;
int i1, i2, len0, len1;

len0 = len1 = 0;

try {
for (i1 = i2 = 0; i1 < realLength; len0 = ++i1) {
// Do not coarsen the "safe" check, since it will misinterpret AIOOBE from the yield
// See JRUBY-5434
IRubyObject v = safeArrayRef(values, begin + i1);
if (block.yield(context, v).isTrue()) continue;
if (i1 != i2) {
store(i2, v);
}
len1 = ++i2;
}

return (i1 == i2) ? context.nil : this;
} finally {
selectBangEnsure(len0, len1);
}
}

return result;
// MRI: select_bang_ensure
private void selectBangEnsure(int len0, int len1) {
int len = size();
int i1 = len0, i2 = len1;

if (i2 < i1) {
if (i1 < len) {
System.arraycopy(values, begin + i1, values, begin + i2, len - i1);
}
realLength = len - i1 + i2;
}
}

@JRubyMethod(name = "reject!")
@@ -2807,8 +2824,12 @@ private boolean flatten(ThreadContext context, int level, RubyArray result) {
IRubyObject tmp;
while (i < ary.realLength) {
IRubyObject elt = ary.values[ary.begin + i++];
if (level >= 0 && stack.size() / 2 >= level) {
result.append(elt);
continue;
}
tmp = TypeConverter.checkArrayType(elt);
if (tmp.isNil() || (level >= 0 && stack.realLength / 2 >= level)) {
if (tmp.isNil()) {
result.append(elt);
} else {
modified = true;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyObject.java
Original file line number Diff line number Diff line change
@@ -571,7 +571,7 @@ static IRubyObject dig(ThreadContext context, IRubyObject obj, IRubyObject[] arg
return obj.callMethod(context, "dig", rest);
}
}
return context.nil; // can not dig further (there's still args left)
throw context.runtime.newTypeError(obj.getMetaClass().getName() + " does not have #dig method");
}

/**
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/ast/CallNode.java
Original file line number Diff line number Diff line change
@@ -134,4 +134,9 @@ public boolean isLazy() {
public List<Node> childNodes() {
return Node.createList(receiverNode, argsNode, iterNode);
}

@Override
protected String toStringInternal() {
return isLazy ? "lazy" : null;
}
}
17 changes: 17 additions & 0 deletions core/src/main/java/org/jruby/ast/Node.java
Original file line number Diff line number Diff line change
@@ -139,6 +139,10 @@ public String toString(boolean indent, int indentation) {

builder.append("(").append(getNodeName());

String moreState = toStringInternal();

if (moreState != null) builder.append("[").append(moreState).append("]");

if (this instanceof INameNode) builder.append(":").append(((INameNode) this).getName());

builder.append(" ").append(getPosition().getLine());
@@ -172,6 +176,19 @@ public String toString(boolean indent, int indentation) {
return builder.toString();
}

/**
* Overridden by nodes that have additional internal state to be displated in toString.
*
* For nodes that have it, name is handled separately, by implementing INameNode.
*
* Child nodes are handled via iterating #childNodes.
*
* @return A string representing internal node state, or null if none.
*/
protected String toStringInternal() {
return null;
}

private static void indent(int indentation, StringBuilder builder) {
for (int n = 0; n < indentation; n++) {
builder.append(" ");
4 changes: 4 additions & 0 deletions test/mri/excludes/TestExcludes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude :test_safe_call_block_command, "needs parser work"
exclude :test_safe_call_block_call, "needs parser work"
exclude :test_safe_call_block_call_brace, "needs parser work"
exclude :test_safe_call_block_call_command, "needs parser work"