Skip to content

Commit

Permalink
Move array arg list logic into native block calls and remove it from
Browse files Browse the repository at this point in the history
RubyProc.prepareArguments since pure-Ruby code does not need it.

There is some amount of risk to removing this but with the code in place
I would have needed to make additional changes to keep it there and so I
am going for it...
enebo committed Dec 7, 2016
1 parent 9dfb955 commit 509dd05
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.InternalVariables;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ArraySupport;
import org.jruby.util.TypeConverter;

import java.util.ArrayList;
7 changes: 0 additions & 7 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -49,9 +49,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.DataType;
import org.jruby.util.ArraySupport;

import java.util.Arrays;

/**
* @author jpetersen
@@ -266,10 +263,6 @@ public static IRubyObject[] prepareArgs(ThreadContext context, Block.Type type,
int arityValue = blockBody.getSignature().arityValue();
if (args.length == 1 && (arityValue < -1 || arityValue > 1)) args = IRRuntimeHelpers.toAry(context, args);

// FIXME: This pruning only seems to be needed for calls through java block/calls CallBlock/JavaInternalBlockBody (move to those since pure-Ruby does not seem to need this.
// fixed arity > 0 with mismatch needs a new args array
if (arityValue > 0 && arityValue != args.length) args = ArraySupport.newCopy(args, arityValue);

return args;
}

6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/runtime/CallBlock.java
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ArraySupport;

/**
* A Block implemented using a Java-based BlockCallback implementation. For
@@ -84,6 +85,11 @@ protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject va

@Override
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
Signature signature = block.getSignature();
int required = signature.required();
if (signature.isFixed() && required > 0 && required != args.length) {
args = ArraySupport.newCopy(args, required);
}
return callback.call(context, args, Block.NULL_BLOCK);
}

Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import org.jruby.Ruby;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ArraySupport;

/**
* Represents a special Java implementation of a block.
@@ -66,7 +67,12 @@ protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject va
@Override
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
threadCheck(context);


Signature signature = block.getSignature();
int required = signature.required();
if (signature.isFixed() && required > 0 && required != args.length) {
args = ArraySupport.newCopy(args, required);
}
return yield(context, args);
}

0 comments on commit 509dd05

Please sign in to comment.