Skip to content

Commit

Permalink
Call-site cache remaining callMethod in Set
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Aug 22, 2023
1 parent f6b3ca7 commit 73dbef0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
19 changes: 10 additions & 9 deletions core/src/main/java/org/jruby/ext/set/RubySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject enume, Block bl
}

allocHash(context.runtime);
return callMethod(context, "merge", enume); // TODO site-cache
return sites(context).merge.call(context, this, this, enume); // TODO site-cache
}

protected IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
Expand Down Expand Up @@ -251,11 +251,12 @@ IRubyObject yieldImpl(ThreadContext context, IRubyObject val) {

// set.rb do_with_enum (block is required)
private static IRubyObject doWithEnum(final ThreadContext context, final IRubyObject enume, final EachBody blockImpl) {
if ( enume.respondsTo("each_entry") ) {
return enume.callMethod(context, "each_entry", IRubyObject.NULL_ARRAY, new Block(blockImpl));
JavaSites.SetSites sites = sites(context);
if ( sites.respond_to_each_entry.respondsTo(context, enume, enume) ) {
return sites.each_entry.call(context, enume, enume, new Block(blockImpl));
}
if ( enume.respondsTo("each") ) {
return enume.callMethod(context, "each", IRubyObject.NULL_ARRAY, new Block(blockImpl));
if ( sites.respond_to_each.respondsTo(context, enume, enume) ) {
return sites.each.call(context, enume, enume, new Block(blockImpl));
}

throw context.runtime.newArgumentError("value must be enumerable");
Expand All @@ -274,7 +275,7 @@ public IRubyObject instance_variable_set(IRubyObject name, IRubyObject value) {
}

IRubyObject invokeAdd(final ThreadContext context, final IRubyObject val) {
return this.callMethod(context,"add", val); // TODO site-cache
return sites(context).add.call(context, this, this, val);
}

private static abstract class EachBody extends JavaInternalBlockBody {
Expand Down Expand Up @@ -445,7 +446,7 @@ private void flattenMerge(final ThreadContext context, final IRubyObject set, fi
}
}
else {
set.callMethod(context, "each", IRubyObject.NULL_ARRAY, new Block(
sites(context).each.call(context, set, set, new Block(
new EachBody(context.runtime) {
IRubyObject yieldImpl(ThreadContext context, IRubyObject e) {
addFlattened(context, seen, e); return context.nil;
Expand Down Expand Up @@ -1017,7 +1018,7 @@ private IRubyObject divideTSort(ThreadContext context, final Block block) {
final RubyClass Set = runtime.getClass("Set");
final RubySet set = new RubySet(runtime, Set);
set.allocHash(runtime, dig.size());
dig.callMethod(context, "each_strongly_connected_component", IRubyObject.NULL_ARRAY, new Block(
sites(context).each_strongly_connected_component.call(context, this, dig, new Block(
new JavaInternalBlockBody(runtime, Signature.ONE_REQUIRED) {
@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
Expand Down Expand Up @@ -1087,7 +1088,7 @@ public IRubyObject tsort_each_child(ThreadContext context, IRubyObject node, Blo
return ((RubySet) set).each(context, block);
}
// some Enumerable (we do not expect this to happen)
return set.callMethod(context, "each", IRubyObject.NULL_ARRAY, block);
return sites(context).each.call(context, this, set, block);
}

}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,13 @@ public static class SetSites {
public final CallSite proper_superset = new FunctionalCachingCallSite("proper_superset?");
public final CallSite to_a = new FunctionalCachingCallSite("to_a");
public final CallSite ary_join = new FunctionalCachingCallSite("join");
public final CallSite add = new FunctionalCachingCallSite("add");
public final CallSite each_strongly_connected_component = new FunctionalCachingCallSite("each_strongly_connected_component");
public final CallSite each = new FunctionalCachingCallSite("each");
public final RespondToCallSite respond_to_each = new RespondToCallSite("each");
public final CallSite each_entry = new FunctionalCachingCallSite("each_entry");
public final RespondToCallSite respond_to_each_entry = new RespondToCallSite("each_entry");
public final CallSite merge = new FunctionalCachingCallSite("merge");
}

public static class CheckedSites {
Expand Down

0 comments on commit 73dbef0

Please sign in to comment.