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...
  • Loading branch information
enebo committed Dec 7, 2016
1 parent 9dfb955 commit 509dd05
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/org/jruby/RubyProc.java
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/runtime/CallBlock.java
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 509dd05

Please sign in to comment.