Skip to content

Commit

Permalink
Split Method#curry
Browse files Browse the repository at this point in the history
It redispatches to Proc#curry, which currently is in Ruby and
still boxes the arguments, but we're kicking the can down the road
a bit.
  • Loading branch information
headius committed Jan 4, 2024
1 parent 7977560 commit 53ff1f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
24 changes: 21 additions & 3 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.MethodBlockBody;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.PositionAware;
Expand Down Expand Up @@ -364,9 +365,16 @@ public IRubyObject parameters(ThreadContext context) {
return Helpers.methodToParameters(context.runtime, this);
}

@JRubyMethod(optional = 1, checkArity = false)
public IRubyObject curry(ThreadContext context, IRubyObject[] args) {
return to_proc(context).callMethod(context, "curry", args);
@JRubyMethod
public IRubyObject curry(ThreadContext context, IRubyObject arg0) {
IRubyObject proc = to_proc(context);
return sites(context).curry.call(context, proc, proc, arg0);
}

@JRubyMethod
public IRubyObject curry(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
IRubyObject proc = to_proc(context);
return sites(context).curry.call(context, proc, proc, arg0, arg1);
}

@JRubyMethod
Expand Down Expand Up @@ -397,5 +405,15 @@ public IRubyObject getReceiver() {
return receiver;
}

@Deprecated
public IRubyObject curry(ThreadContext context, IRubyObject[] args) {
IRubyObject proc = to_proc(context);
return sites(context).curry.call(context, proc, proc, args);
}

private static JavaSites.MethodSites sites(ThreadContext context) {
return context.sites.Method;
}

}

5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class JavaSites {
public final SetSites Set = new SetSites();
public final StructSites Struct = new StructSites();
public final DigestSites Digest = new DigestSites();
public final MethodSites Method = new MethodSites();

public static class BasicObjectSites {
public final CallSite respond_to = new FunctionalCachingCallSite("respond_to?");
Expand Down Expand Up @@ -546,6 +547,10 @@ public static class DigestSites {
public final CallSite digest_length = new FunctionalCachingCallSite("digest_length");
}

public static class MethodSites {
public final CallSite curry = new FunctionalCachingCallSite("curry");
}

public static class CheckedSites {
public final RespondToCallSite respond_to_X;
public final CachingCallSite respond_to_missing = new FunctionalCachingCallSite("respond_to_missing?");
Expand Down

0 comments on commit 53ff1f2

Please sign in to comment.