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

Commits on Dec 8, 2016

  1. Implemented Hash#compact and Hash#compact!

    It passes the TestHash#test_compact method of the MRI test.
    herwinw committed Dec 8, 2016
    Copy the full SHA
    8d3cd0c View commit details
  2. Merge pull request #4368 from herwinw/hash_compact

    Implemented Hash#compact and Hash#compact!
    headius authored Dec 8, 2016
    Copy the full SHA
    b76218b View commit details
Showing with 25 additions and 0 deletions.
  1. +25 −0 core/src/main/java/org/jruby/RubyHash.java
25 changes: 25 additions & 0 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -1866,6 +1866,31 @@ public IRubyObject flatten(ThreadContext context, IRubyObject level) {
return ary;
}

@JRubyMethod(name = "compact")
public IRubyObject compact(ThreadContext context) {
IRubyObject res = dup();
((RubyHash)res).compact_bang(context);
return res;
}

@JRubyMethod(name = "compact!")
public IRubyObject compact_bang(ThreadContext context) {
boolean changed = false;
modify();
iteratorEntry();
try {
for (RubyHashEntry entry = head.nextAdded; entry != head; entry = entry.nextAdded) {
if (entry.value == context.nil) {
internalDelete(entry.key);
changed = true;
}
}
} finally {
iteratorExit();
}
return changed ? this : context.nil;
}

@JRubyMethod(name = "compare_by_identity")
public IRubyObject getCompareByIdentity(ThreadContext context) {
modify();