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: ab75bbb24128
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9504a1c1f552
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 8, 2018

  1. Fix Hash#reject

    In MRI, `Hash#reject`
    
    * creates new hash
    * sets keys & values if block returns false
    
    This commit will fix `#test_reject`.
    
    Ref: https://github.com/ruby/ruby/blob/v2_4_0/hash.c#L1328
    yui-knk committed Jan 8, 2018
    Copy the full SHA
    5def73d View commit details
  2. Merge pull request #4951 from yui-knk/test_reject

    Fix `Hash#reject`
    enebo authored Jan 8, 2018
    Copy the full SHA
    9504a1c View commit details
Showing with 19 additions and 2 deletions.
  1. +19 −1 core/src/main/java/org/jruby/RubyHash.java
  2. +0 −1 test/mri/excludes/TestHash.rb
20 changes: 19 additions & 1 deletion core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -1694,11 +1694,29 @@ public IRubyObject delete_if(final ThreadContext context, final Block block) {
return block.isGiven() ? delete_ifInternal(context, block) : enumeratorizeWithSize(context, this, "delete_if", enumSizeFn());
}

private static final class RejectVisitor extends VisitorWithState<Block> {
final RubyHash result;
RejectVisitor(RubyHash result) {
this.result = result;
}

@Override
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) {
if (!block.yieldArray(context, RubyArray.newArray(context.runtime, key, value), null).isTrue()) {
result.fastASet(key, value);
}
}
}

/** rb_hash_reject
*
*/
public RubyHash rejectInternal(ThreadContext context, Block block) {
return ((RubyHash)dup()).delete_ifInternal(context, block);
final RubyHash result = newHash(context.runtime);

iteratorVisitAll(context, new RejectVisitor(result), block);

return result;
}

@JRubyMethod
1 change: 0 additions & 1 deletion test/mri/excludes/TestHash.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
exclude :test_inverse_hash, "needs investigation"
exclude :test_NEWHASH_fstring_key, "needs investigation"
exclude :test_recursive_hash_value_struct, "needs investigation"
exclude :test_reject, "needs investigation"
exclude :test_AREF_fstring_key, "Depends on MRI-specific GC.stat key"
exclude :test_ASET_fstring_key, "due https://github.com/jruby/jruby/commit/f3f0091da7d98c5df285"