Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5f37238d483b
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7998429d03cf
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Jul 6, 2016

  1. Copy the full SHA
    6bdcd7a View commit details
  2. Copy the full SHA
    7998429 View commit details
8 changes: 3 additions & 5 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -3507,13 +3507,11 @@ public IRubyObject sort_by_bang(ThreadContext context, Block block) {
if (!block.isGiven()) return enumeratorizeWithSize(context, this, "sort_by!", enumLengthFn());

modifyCheck();
unpack();

RubyArray sorted = Helpers.invoke(context, this, "sort_by", block).convertToArray();
sorted.unpack();
values = sorted.values;
isShared = false;
begin = 0;

replace(sorted);

return this;
}

Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CachingCallSite;
import org.jruby.runtime.ivars.VariableAccessor;
import org.jruby.specialized.RubyArraySpecialized;
import org.jruby.util.ByteList;
import org.jruby.util.JavaNameMangler;
import org.jruby.util.RegexpOptions;
@@ -847,7 +848,7 @@ public void array(int length) {
if (length > MAX_ARGUMENTS) throw new NotCompilableException("literal array has more than " + MAX_ARGUMENTS + " elements");

// use utility method for supported sizes
if (length < 3) {
if (length <= RubyArraySpecialized.MAX_PACKED_SIZE) {
invokeIRHelper("newArray", sig(RubyArray.class, params(ThreadContext.class, IRubyObject.class, length)));
return;
}
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.specialized.RubyArraySpecialized;
import org.jruby.util.ByteList;
import org.jruby.util.JavaNameMangler;
import org.jruby.util.RegexpOptions;
@@ -295,7 +296,7 @@ public void array(int length) {
if (length > MAX_ARGUMENTS) throw new NotCompilableException("literal array has more than " + MAX_ARGUMENTS + " elements");

// use utility method for supported sizes
if (length < 3) {
if (length <= RubyArraySpecialized.MAX_PACKED_SIZE) {
super.array(length);
return;
}
20 changes: 20 additions & 0 deletions core/src/main/java/org/jruby/specialized/RubyArrayOneObject.java
Original file line number Diff line number Diff line change
@@ -238,6 +238,26 @@ public IRubyObject op_plus(IRubyObject obj) {
return super.op_plus(y);
}

@Override
public IRubyObject replace(IRubyObject orig) {
if (!packed()) return super.replace(orig);

modifyCheck();

RubyArray origArr = orig.convertToArray();

if (this == orig) return this;

if (origArr.size() == 1) {
value = origArr.eltInternal(0);
return this;
}

unpack();

return super.replace(origArr);
}

@Override
public IRubyObject reverse_bang() {
if (!packed()) return super.reverse_bang();
Original file line number Diff line number Diff line change
@@ -46,6 +46,8 @@
* RubyArray{@link #uniq(org.jruby.runtime.ThreadContext)}
*/
public abstract class RubyArraySpecialized extends RubyArray {
public static final int MAX_PACKED_SIZE = 2;

public RubyArraySpecialized(Ruby runtime, boolean light) {
super(runtime, runtime.getArray(), light);
}
21 changes: 21 additions & 0 deletions core/src/main/java/org/jruby/specialized/RubyArrayTwoObject.java
Original file line number Diff line number Diff line change
@@ -240,6 +240,27 @@ public IRubyObject op_plus(IRubyObject obj) {
return super.op_plus(y);
}

@Override
public IRubyObject replace(IRubyObject orig) {
if (!packed()) return super.replace(orig);

modifyCheck();

RubyArray origArr = orig.convertToArray();

if (this == orig) return this;

if (origArr.size() == 2) {
car = origArr.eltInternal(0);
cdr = origArr.eltInternal(0);
return this;
}

unpack();

return super.replace(origArr);
}

@Override
public IRubyObject reverse_bang() {
if (!packed()) return super.reverse_bang();