Skip to content

Commit

Permalink
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
@@ -54,6 +54,14 @@
import org.jruby.runtime.ObjectMarshal;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;

import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.runtime.Helpers.hashEnd;
import static org.jruby.runtime.Helpers.hashStart;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.Helpers.murmurCombine;
import static org.jruby.runtime.Helpers.safeHash;

import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.builtin.Variable;
import org.jruby.runtime.callsite.RespondToCallSite;
@@ -67,7 +75,6 @@
import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.RubyNumeric.intervalStepSize;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.Visibility.PRIVATE;

/**
@@ -287,15 +294,21 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject original)

@JRubyMethod(name = "hash")
public RubyFixnum hash(ThreadContext context) {
long hash = isExclusive ? 1 : 0;
long h = hash;

long v = invokedynamic(context, begin, MethodNames.HASH).convertToInteger().getLongValue();
hash ^= v << 1;
v = invokedynamic(context, end, MethodNames.HASH).convertToInteger().getLongValue();
hash ^= v << 9;
hash ^= h << 24;
return context.runtime.newFixnum(hash);
Ruby runtime = context.runtime;

int exclusiveBit = isExclusive ? 1 : 0;
long hash = exclusiveBit;
IRubyObject v;

hash = hashStart(runtime, hash);
v = safeHash(context, begin);
hash = murmurCombine(hash, v.convertToInteger().getLongValue());
v = safeHash(context, end);
hash = murmurCombine(hash, v.convertToInteger().getLongValue());
hash = murmurCombine(hash, exclusiveBit << 24);
hash = hashEnd(hash);

return runtime.newFixnum(hash);
}

private static RubyString inspectValue(final ThreadContext context, IRubyObject value) {
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/ipaddr.rb
Original file line number Diff line number Diff line change
@@ -352,7 +352,7 @@ def eql?(other)

# Returns a hash value used by Hash, Set, and Array classes
def hash
return [@addr, @mask_addr].hash ^ (ipv4? ? 0 : 1)
return ([@addr, @mask_addr].hash << 1) | (ipv4? ? 0 : 1)
end

# Creates a Range object for the network address.

0 comments on commit a0fd348

Please sign in to comment.