Skip to content

Commit

Permalink
Remove Ruby as argument to newRange
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Nov 5, 2014
1 parent 80727e1 commit 502e659
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyArray.java
Expand Up @@ -1324,7 +1324,7 @@ private IRubyObject arefCommon(IRubyObject arg0) {
IRubyObject begin = arg0.callMethod(context, "begin");
IRubyObject end = arg0.callMethod(context, "end");
IRubyObject excl = arg0.callMethod(context, "exclude_end?");
RubyRange range = RubyRange.newRange(runtime, context, begin, end, excl.isTrue());
RubyRange range = RubyRange.newRange(context, begin, end, excl.isTrue());

long[] beglen = range.begLen(realLength, 0);
return beglen == null ? runtime.getNil() : subseq(beglen[0], beglen[1]);
Expand Down Expand Up @@ -1380,7 +1380,7 @@ public IRubyObject aset19(IRubyObject arg0, IRubyObject arg1) {
IRubyObject begin = arg0.callMethod(context, "begin");
IRubyObject end = arg0.callMethod(context, "end");
IRubyObject excl = arg0.callMethod(context, "exclude_end?");
RubyRange range = RubyRange.newRange(context.runtime, context, begin, end, excl.isTrue());
RubyRange range = RubyRange.newRange(context, begin, end, excl.isTrue());

long beg = range.begLen0(realLength);
splice(beg, range.begLen1(realLength, beg), arg1, true);
Expand Down
16 changes: 2 additions & 14 deletions core/src/main/java/org/jruby/RubyRange.java
Expand Up @@ -109,24 +109,12 @@ private RubyRange(Ruby runtime, RubyClass klass) {
begin = end = runtime.getNil();
}

public static RubyRange newRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
public static RubyRange newRange(ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) {
RubyRange range = new RubyRange(context.runtime, context.runtime.getRange());
range.init(context, begin, end, isExclusive);
return range;
}

public static RubyRange newExclusiveRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, true);
return range;
}

public static RubyRange newInclusiveRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, false);
return range;
}

@Override
public void copySpecialInstanceVariables(IRubyObject clone) {
RubyRange range = (RubyRange)clone;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -3061,7 +3061,7 @@ private IRubyObject byteARef(Ruby runtime, IRubyObject idx) {
IRubyObject begin = idx.callMethod(context, "begin");
IRubyObject end = idx.callMethod(context, "end");
IRubyObject excl = idx.callMethod(context, "exclude_end?");
RubyRange range = RubyRange.newRange(runtime, context, begin, end, excl.isTrue());
RubyRange range = RubyRange.newRange(context, begin, end, excl.isTrue());

int[] begLen = range.begLenInt(getByteList().length(), 0);
return begLen == null ? runtime.getNil() : byteSubstr(runtime, begLen[0], begLen[1]);
Expand Down Expand Up @@ -3225,7 +3225,7 @@ public IRubyObject op_aref19(ThreadContext context, IRubyObject arg) {
IRubyObject begin = arg.callMethod(context, "begin");
IRubyObject end = arg.callMethod(context, "end");
IRubyObject excl = arg.callMethod(context, "exclude_end?");
RubyRange range = RubyRange.newRange(runtime, context, begin, end, excl.isTrue());
RubyRange range = RubyRange.newRange(context, begin, end, excl.isTrue());

int[] begLen = range.begLenInt(len, 0);
return begLen == null ? runtime.getNil() : substr19(runtime, begLen[0], begLen[1]);
Expand Down Expand Up @@ -3350,7 +3350,7 @@ public IRubyObject op_aset19(ThreadContext context, IRubyObject arg0, IRubyObjec
IRubyObject begin = arg0.callMethod(context, "begin");
IRubyObject end = arg0.callMethod(context, "end");
IRubyObject excl = arg0.callMethod(context, "exclude_end?");
RubyRange rng = RubyRange.newRange(context.runtime, context, begin, end, excl.isTrue());
RubyRange rng = RubyRange.newRange(context, begin, end, excl.isTrue());

int[] begLen = rng.begLenInt(strLength(), 2);
replaceInternal19(begLen[0], begLen[1], arg1.convertToString());
Expand Down
Expand Up @@ -79,7 +79,7 @@ public Instr clone(CloneInfo ii) {

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
return RubyRange.newRange(context.runtime, context,
return RubyRange.newRange(context,
(IRubyObject) begin.retrieve(context, self, currScope, currDynScope, temp),
(IRubyObject) end.retrieve(context, self, currScope, currDynScope, temp), exclusive);
}
Expand Down

0 comments on commit 502e659

Please sign in to comment.