Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ protected SizeFn enumLengthFn() {
final RubyArray self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return self.length();
}
};
Expand Down Expand Up @@ -3800,7 +3800,7 @@ private SizeFn cycleSizeFn(final ThreadContext context) {
return new SizeFn() {
CallSite op_times = sites(context).op_times;
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
Ruby runtime = context.runtime;
IRubyObject n = runtime.getNil();

Expand Down Expand Up @@ -3957,7 +3957,7 @@ private SizeFn combinationSize(final ThreadContext context) {
final RubyArray self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
long n = self.realLength;
assert args != null && args.length > 0 && args[0] instanceof RubyNumeric; // #combination ensures arg[0] is numeric
long k = ((RubyNumeric) args[0]).getLongValue();
Expand Down Expand Up @@ -4010,7 +4010,7 @@ private SizeFn repeatedCombinationSize(final ThreadContext context) {
final RubyArray self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context1, IRubyObject recv, IRubyObject[] args) {
long n = self.realLength;
assert args != null && args.length > 0 && args[0] instanceof RubyNumeric; // #repeated_combination ensures arg[0] is numeric
long k = ((RubyNumeric) args[0]).getLongValue();
Expand Down Expand Up @@ -4107,7 +4107,7 @@ private SizeFn repeatedPermutationSize(final ThreadContext context) {
return new SizeFn() {
CallSite op_exp = sites(context).op_exp;
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
RubyFixnum n = self.length();
assert args != null && args.length > 0 && args[0] instanceof RubyNumeric; // #repeated_permutation ensures arg[0] is numeric
long k = ((RubyNumeric) args[0]).getLongValue();
Expand Down Expand Up @@ -4152,7 +4152,7 @@ private SizeFn permutationSize(final ThreadContext context) {

return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context1, IRubyObject recv, IRubyObject[] args) {
long n = self.realLength;
long k;

Expand Down
21 changes: 9 additions & 12 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@
import org.jruby.runtime.CallBlock19;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.JavaInternalBlockBody;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.JavaSites.EnumerableSites;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.InternalVariables;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.NormalCachingCallSite;
import org.jruby.util.ArraySupport;
import org.jruby.runtime.builtin.InternalVariables;
import org.jruby.util.TypeConverter;

import java.util.ArrayList;
Expand All @@ -58,12 +55,12 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.RubyEnumerator.enumeratorize;
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.RubyObject.equalInternal;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.invokedynamic.MethodNames.OP_CMP;
import static org.jruby.RubyEnumerator.SizeFn;

/**
* The implementation of Ruby's Enumerable module.
Expand Down Expand Up @@ -260,7 +257,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
private static SizeFn cycleSizeFn(final ThreadContext context, final IRubyObject self) {
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
long mul = 0;
IRubyObject n = runtime.getNil();
Expand All @@ -270,7 +267,7 @@ public IRubyObject size(IRubyObject[] args) {
if (!n.isNil()) mul = n.convertToInteger().getLongValue();
}

IRubyObject size = enumSizeFn(context, self).size(args);
IRubyObject size = enumSizeFn(context, self).size(context, self, args);
if (size == null || size.isNil() || size.equals(RubyFixnum.zero(runtime))) {
return size;
}
Expand Down Expand Up @@ -1242,15 +1239,15 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
private static SizeFn eachSliceSizeFn(final ThreadContext context, final IRubyObject self) {
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
Ruby runtime = context.runtime;
assert args != null && args.length > 0 && args[0] instanceof RubyNumeric; // #each_slice ensures arg[0] is numeric
long sliceSize = ((RubyNumeric) args[0]).getLongValue();
if (sliceSize <= 0) {
throw runtime.newArgumentError("invalid slice size");
}

IRubyObject size = enumSizeFn(context, self).size(args);
IRubyObject size = enumSizeFn(context, self).size(context, self, args);
if (size == null || size.isNil()) {
return runtime.getNil();
}
Expand Down Expand Up @@ -1292,15 +1289,15 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
private static SizeFn eachConsSizeFn(final ThreadContext context, final IRubyObject self) {
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context1, IRubyObject self, IRubyObject[] args) {
Ruby runtime = context.runtime;
assert args != null && args.length > 0 && args[0] instanceof RubyNumeric; // #each_cons ensures arg[0] is numeric
long consSize = ((RubyNumeric) args[0]).getLongValue();
if (consSize <= 0) {
throw runtime.newArgumentError("invalid size");
}

IRubyObject size = enumSizeFn(context, self).size(args);
IRubyObject size = enumSizeFn(context, self).size(context1, self, args);
if (size == null || size.isNil()) {
return runtime.getNil();
}
Expand Down Expand Up @@ -2109,7 +2106,7 @@ public static IRubyObject chunk(ThreadContext context, IRubyObject self, final B
private static SizeFn enumSizeFn(final ThreadContext context, final IRubyObject self) {
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
IRubyObject size = self.checkCallMethod(context, sites(context).size_checked);
return size == null ? context.nil : size;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public IRubyObject each_cons(ThreadContext context, IRubyObject arg, final Block
@JRubyMethod
public final IRubyObject size(ThreadContext context) {
if (sizeFn != null) {
return sizeFn.size(methodArgs);
return sizeFn.size(context, this, methodArgs);
}

IRubyObject size = this.size;
Expand Down Expand Up @@ -476,7 +476,7 @@ private SizeFn enumSizeFn(final ThreadContext context) {
final RubyEnumerator self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return self.size(context);
}
};
Expand Down Expand Up @@ -641,7 +641,7 @@ public Spliterator<Object> spliterator(final int mod) {
* TODO (CON): fix this to receive context and state to we're not reallocating it all the time
*/
public interface SizeFn {
IRubyObject size(IRubyObject[] args);
IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args);
}

private static abstract class Nexter {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ private SizeFn enumSizeFn() {
final RubyHash self = this;
return new RubyEnumerator.SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context1, IRubyObject recv, IRubyObject[] args) {
return self.rb_size();
}
};
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
import java.math.BigInteger;
import java.math.RoundingMode;

import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.util.Numeric.*;
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.util.Numeric.checkInteger;
import static org.jruby.util.Numeric.f_gcd;
import static org.jruby.util.Numeric.f_lcm;

/** Implementation of the Integer class.
*
Expand Down Expand Up @@ -252,7 +254,7 @@ private static void duckUpto(ThreadContext context, IRubyObject from, IRubyObjec
private static SizeFn uptoSize(final ThreadContext context, final IRubyObject from, final IRubyObject to) {
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return intervalStepSize(context, from, to, RubyFixnum.one(context.runtime), false);
}
};
Expand Down Expand Up @@ -314,7 +316,7 @@ private static void duckDownto(ThreadContext context, IRubyObject from, IRubyObj
private static SizeFn downToSize(final ThreadContext context, final IRubyObject from, final IRubyObject to) {
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return intervalStepSize(context, from, to, RubyFixnum.newFixnum(context.runtime, -1), false);
}
};
Expand Down Expand Up @@ -343,7 +345,7 @@ protected SizeFn timesSizeFn(final Ruby runtime) {
final RubyInteger self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context1, IRubyObject recv, IRubyObject[] args) {
RubyFixnum zero = RubyFixnum.zero(runtime);
ThreadContext context = runtime.getCurrentContext();
if ((self instanceof RubyFixnum && getLongValue() < 0)
Expand Down
19 changes: 12 additions & 7 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallType;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.JavaSites.KernelSites;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.backtrace.BacktraceElement;
import org.jruby.runtime.backtrace.RubyStackTraceElement;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ArraySupport;
Expand All @@ -87,16 +86,22 @@
import java.util.Set;

import static org.jruby.RubyBasicObject.UNDEF;
import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.anno.FrameField.BACKREF;
import static org.jruby.anno.FrameField.BLOCK;
import static org.jruby.anno.FrameField.CLASS;
import static org.jruby.anno.FrameField.FILENAME;
import static org.jruby.anno.FrameField.JUMPTARGET;
import static org.jruby.anno.FrameField.LASTLINE;
import static org.jruby.anno.FrameField.LINE;
import static org.jruby.anno.FrameField.METHODNAME;
import static org.jruby.anno.FrameField.SCOPE;
import static org.jruby.anno.FrameField.SELF;
import static org.jruby.anno.FrameField.VISIBILITY;
import static org.jruby.runtime.Visibility.PRIVATE;
import static org.jruby.runtime.Visibility.PROTECTED;
import static org.jruby.runtime.Visibility.PUBLIC;
import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.anno.FrameField.*;

/**
* Note: For CVS history, see KernelModule.java.
Expand Down Expand Up @@ -1411,7 +1416,7 @@ public static RubyProc proc_1_9(ThreadContext context, IRubyObject recv, Block b
@JRubyMethod(name = "loop", module = true, visibility = PRIVATE)
public static IRubyObject loop(ThreadContext context, IRubyObject recv, Block block) {
if ( ! block.isGiven() ) {
return RubyEnumerator.enumeratorizeWithSize(context, recv, "loop", loopSizeFn(context));
return enumeratorizeWithSize(context, recv, "loop", loopSizeFn(context));
}
final Ruby runtime = context.runtime;
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
Expand All @@ -1437,7 +1442,7 @@ public static IRubyObject loop(ThreadContext context, IRubyObject recv, Block bl
private static SizeFn loopSizeFn(final ThreadContext context) {
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return RubyFloat.newFloat(context.runtime, RubyFloat.INFINITY);
}
};
Expand Down Expand Up @@ -1893,7 +1898,7 @@ public static IRubyObject obj_to_enum(final ThreadContext context, IRubyObject s
if (block.isGiven()) {
sizeFn = new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return block.call(context, args);
}
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ private SizeFn stepSizeFn(final ThreadContext context, final IRubyObject from, f
return new SizeFn() {
// MRI: num_step_size
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context, IRubyObject self, IRubyObject[] args) {
IRubyObject[] newArgs = new IRubyObject[2];
scanStepArgs(context, args, newArgs);
return intervalStepSize(context, from, newArgs[0], newArgs[1], false);
Expand Down
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

package org.jruby;


import java.io.IOException;
import java.util.List;
import org.jcodings.Encoding;
Expand Down Expand Up @@ -73,9 +74,14 @@
import org.jruby.util.ByteList;
import org.jruby.util.TypeConverter;

import java.io.IOException;
import java.util.List;

import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.RubyNumeric.intervalStepSize;
import static org.jruby.runtime.Helpers.invokedynamic;

import static org.jruby.runtime.Visibility.PRIVATE;

/**
Expand Down Expand Up @@ -642,7 +648,7 @@ private SizeFn enumSizeFn(final ThreadContext context) {
final RubyRange self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context1, IRubyObject recv, IRubyObject[] args) {
return self.size(context);
}
};
Expand All @@ -652,7 +658,7 @@ private SizeFn stepSizeFn(final ThreadContext context) {
final RubyRange self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
public IRubyObject size(ThreadContext context1, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
IRubyObject begin = self.begin;
IRubyObject end = self.end;
Expand Down
Loading