From 73dbef07f45f2696ec206f6272155d9bd889fa14 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 22 Aug 2023 15:55:22 -0500 Subject: [PATCH] Call-site cache remaining callMethod in Set --- .../main/java/org/jruby/ext/set/RubySet.java | 19 ++++++++++--------- .../java/org/jruby/runtime/JavaSites.java | 7 +++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/jruby/ext/set/RubySet.java b/core/src/main/java/org/jruby/ext/set/RubySet.java index cfb6c088e1c..8b67eeb55b1 100644 --- a/core/src/main/java/org/jruby/ext/set/RubySet.java +++ b/core/src/main/java/org/jruby/ext/set/RubySet.java @@ -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) { @@ -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"); @@ -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 { @@ -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; @@ -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) { @@ -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); } } diff --git a/core/src/main/java/org/jruby/runtime/JavaSites.java b/core/src/main/java/org/jruby/runtime/JavaSites.java index 91b203aa1bc..b99f7581118 100644 --- a/core/src/main/java/org/jruby/runtime/JavaSites.java +++ b/core/src/main/java/org/jruby/runtime/JavaSites.java @@ -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 {