Skip to content

Commit

Permalink
Showing 4 changed files with 17 additions and 39 deletions.
33 changes: 11 additions & 22 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -801,15 +801,11 @@ public IRubyObject fetch(ThreadContext context, IRubyObject arg0, IRubyObject ar
/** rb_ary_to_ary
*
*/
private static RubyArray aryToAry(IRubyObject obj) {
if (obj instanceof RubyArray) return (RubyArray) obj;
public static RubyArray aryToAry(IRubyObject obj) {
IRubyObject tmp = TypeConverter.checkArrayType(obj);

if (obj.respondsTo("to_ary")) return obj.convertToArray();

RubyArray arr = new RubyArray(obj.getRuntime(), false); // possibly should not in object space
arr.values = new IRubyObject[]{obj};
arr.realLength = 1;
return arr;
if (!tmp.isNil()) return (RubyArray)tmp;
return obj.getRuntime().newArray(obj);
}

/** rb_ary_splice
@@ -1053,24 +1049,17 @@ public IRubyObject values_at(IRubyObject[] args) {
*
*/
public IRubyObject subseq(long beg, long len) {
int realLength = this.realLength;
if (beg > realLength || beg < 0 || len < 0) return getRuntime().getNil();

if (beg + len > realLength) {
len = realLength - beg;

if (len < 0) len = 0;
}

if (len == 0) return new RubyArray(getRuntime(), getMetaClass(), IRubyObject.NULL_ARRAY);

return makeShared(begin + (int) beg, (int) len, getMetaClass());
return subseq(getMetaClass(), beg, len, true);
}

/** rb_ary_subseq
*
*/
public IRubyObject subseqLight(long beg, long len) {
return subseq(getMetaClass(), beg, len, true);
}

public IRubyObject subseq(RubyClass metaClass, long beg, long len, boolean light) {
Ruby runtime = getRuntime();
if (beg > realLength || beg < 0 || len < 0) return runtime.getNil();

@@ -1079,8 +1068,8 @@ public IRubyObject subseqLight(long beg, long len) {
if (len < 0) len = 0;
}

if (len == 0) return new RubyArray(runtime, getMetaClass(), IRubyObject.NULL_ARRAY, false);
return makeShared(begin + (int) beg, (int) len, new RubyArray(runtime, getMetaClass(), false));
if (len == 0) return new RubyArray(runtime, metaClass, IRubyObject.NULL_ARRAY, !light);
return makeShared(begin + (int) beg, (int) len, new RubyArray(runtime, metaClass, !light));
}

/** rb_ary_length
18 changes: 4 additions & 14 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -1338,21 +1338,11 @@ else if (true /**RTEST(flag)**/) { // this logic is only used for bare splat, an
}

public static IRubyObject irToAry(ThreadContext context, IRubyObject value) {
if (value instanceof RubyArray) {
return value;
} else {
IRubyObject newValue = TypeConverter.convertToType19(value, context.runtime.getArray(), "to_ary", false);
if (newValue.isNil()) {
return RubyArray.newArrayLight(context.runtime, value);
}

// must be array by now, or error
if (!(newValue instanceof RubyArray)) {
throw context.runtime.newTypeError(newValue.getMetaClass() + "#" + "to_ary" + " should return Array");
}

return newValue;
if (!(value instanceof RubyArray)) {
value = RubyArray.aryToAry(value);
}

return value;
}

public static int irReqdArgMultipleAsgnIndex(int n, int preArgsCount, int index, int postArgsCount) {
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -292,10 +292,10 @@ public static RubyModule getNthScopeModule(StaticScope scope, int depth) {

public static RubyArray viewArgsArray(ThreadContext context, RubyArray rubyArray, int preArgsCount, int postArgsCount) {
int n = rubyArray.getLength();
if ((preArgsCount >= n) || (preArgsCount + postArgsCount >= n)) {
if (preArgsCount + postArgsCount >= n) {
return RubyArray.newEmptyArray(context.runtime);
} else {
return (RubyArray)rubyArray.subseqLight(preArgsCount, n - preArgsCount - postArgsCount);
return (RubyArray)rubyArray.subseq(context.runtime.getArray(), preArgsCount, n - preArgsCount - postArgsCount, true);
}
}

1 change: 0 additions & 1 deletion spec/tags/ruby/language/variables_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fails:Basic multiple assignment with a splatted single RHS value does not call #to_ary on an object
fails:Basic multiple assignment with a splatted single RHS value calls #to_a even if it's private

fails:Multiple assignment with a single RHS value assigns an Array when the RHS is an Array subclass
fails:Multiple assignment with a MRHS value calls #to_ary to convert a splatted Object when the position receiving the value is a multiple assignment
fails:Multiple assignment with a MRHS value does not call #to_ary to convert a splatted Object when the position receiving the value is a simple variable
fails:Multiple assignment with a MRHS value does not call #to_ary to convert a splatted Object when the position receiving the value is a rest variable

0 comments on commit 0e7d19b

Please sign in to comment.