Skip to content

Commit

Permalink
Showing 2 changed files with 21 additions and 28 deletions.
46 changes: 18 additions & 28 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -47,17 +47,14 @@
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Constants;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.JavaSites.HashSites;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.invokedynamic.MethodNames;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.util.RecursiveComparator;
@@ -74,11 +71,8 @@
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.Visibility.PRIVATE;
import static org.jruby.runtime.invokedynamic.MethodNames.DEFAULT;
import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.runtime.invokedynamic.MethodNames.OP_EQUAL;

// Design overview:
//
@@ -493,10 +487,6 @@ private final void MRICheckResize() {
private static final boolean MRI_HASH = true;
private static final boolean MRI_HASH_RESIZE = true;

protected static int hashValue(final int h) {
return MRI_HASH ? MRIHashValue(h) : JavaSoftHashValue(h);
}

protected final int hashValue(final IRubyObject key) {
final int h = isComparedByIdentity() ? System.identityHashCode(key) : key.hashCode();
return MRI_HASH ? MRIHashValue(h) : JavaSoftHashValue(h);
@@ -710,19 +700,6 @@ public IRubyObject initialize(IRubyObject[] args, final Block block) {
return this;
}

/** rb_hash_default
*
*/
@Deprecated
public IRubyObject default_value_get(ThreadContext context, IRubyObject[] args) {
switch (args.length) {
case 0: return default_value_get(context);
case 1: return default_value_get(context, args[0]);
default:
throw context.runtime.newArgumentError(args.length, 1);
}
}

@JRubyMethod(name = "default")
public IRubyObject default_value_get(ThreadContext context) {
if ((flags & PROCDEFAULT_HASH_F) != 0) {
@@ -734,7 +711,7 @@ public IRubyObject default_value_get(ThreadContext context) {
@JRubyMethod(name = "default")
public IRubyObject default_value_get(ThreadContext context, IRubyObject arg) {
if ((flags & PROCDEFAULT_HASH_F) != 0) {
return Helpers.invoke(context, ifNone, "call", this, arg);
return sites(context).call.call(context, ifNone, ifNone, this, arg);
}
return ifNone == UNDEF ? context.nil : ifNone;
}
@@ -1226,7 +1203,7 @@ public IRubyObject op_eql19(final ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "[]", required = 1)
public IRubyObject op_aref(ThreadContext context, IRubyObject key) {
IRubyObject value;
return ((value = internalGet(key)) == null) ? invokedynamic(context, this, DEFAULT, key) : value;
return ((value = internalGet(key)) == null) ? sites(context).default_.call(context, this, this, key) : value;
}

/** hash_le_i
@@ -1680,7 +1657,7 @@ public IRubyObject shift(ThreadContext context) {
}

if ((flags & PROCDEFAULT_HASH_F) != 0) {
return this.callMethod(context, "default", context.nil);
return sites(context).default_.call(context, this, this, context.nil);
}
return ifNone == UNDEF ? context.nil : ifNone;
}
@@ -1977,14 +1954,14 @@ public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyOb
@JRubyMethod
public IRubyObject flatten(ThreadContext context) {
RubyArray ary = to_a();
ary.callMethod(context, "flatten!", RubyFixnum.one(context.runtime));
sites(context).flatten_bang.call(context, ary, ary, RubyFixnum.one(context.runtime));
return ary;
}

@JRubyMethod
public IRubyObject flatten(ThreadContext context, IRubyObject level) {
RubyArray ary = to_a();
ary.callMethod(context, "flatten!", level);
sites(context).flatten_bang.call(context, ary, ary, level);
return ary;
}

@@ -2602,4 +2579,17 @@ public final void visitAll(Visitor visitor) {
// use -1 to disable concurrency checks
visitLimited(getRuntime().getCurrentContext(), visitor, -1, null);
}

/** rb_hash_default
*
*/
@Deprecated
public IRubyObject default_value_get(ThreadContext context, IRubyObject[] args) {
switch (args.length) {
case 0: return default_value_get(context);
case 1: return default_value_get(context, args[0]);
default:
throw context.runtime.newArgumentError(args.length, 1);
}
}
}
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -141,6 +141,9 @@ public IRubyObject call(ThreadContext context, IRubyObject recv, IRubyObject oth

public static class HashSites {
public final RespondToCallSite respond_to_to_hash = new RespondToCallSite("to_hash");
public final CallSite default_ = new FunctionalCachingCallSite("default");
public final CallSite flatten_bang = new FunctionalCachingCallSite("flatten!");
public final CallSite call = new FunctionalCachingCallSite("call");
}

public static class NumericSites {

0 comments on commit ec4e1fe

Please sign in to comment.