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: 6edb3abce0c9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8ce42e45c7d7
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Mar 14, 2015

  1. Copy the full SHA
    4260ce0 View commit details
  2. Merge pull request #2702 from bjfish/truffle_array_plus_refactoring

    [Truffle] Refactoring Array#+ to handle more cases and adding #to_ary
    chrisseaton committed Mar 14, 2015
    Copy the full SHA
    8ce42e4 View commit details
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/array/plus_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -13,6 +13,14 @@

public class ArrayGuards {

public static boolean isEmpty(RubyArray array) {
return array.getSize() == 0;
}

public static boolean isOtherEmpty(RubyArray array, RubyArray other) {
return other.getSize() == 0;
}

public static boolean isNull(RubyArray array) {
return array.getStore() == null;
}
69 changes: 30 additions & 39 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -55,7 +55,12 @@
public abstract class ArrayNodes {

@CoreMethod(names = "+", required = 1)
public abstract static class AddNode extends ArrayCoreMethodNode {
@NodeChildren({
@NodeChild(value = "a"),
@NodeChild(value = "b")
})
@ImportGuards(ArrayGuards.class)
public abstract static class AddNode extends RubyNode {

public AddNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -65,6 +70,10 @@ public AddNode(AddNode prev) {
super(prev);
}

@CreateCast("b") public RubyNode coerceOtherToAry(RubyNode other) {
return ToAryNodeFactory.create(getContext(), getSourceSection(), other);
}

@Specialization(guards = {"isNull", "isOtherNull"})
public RubyArray addNull(RubyArray a, RubyArray b) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), null, 0);
@@ -129,52 +138,34 @@ public RubyArray addNullObject(RubyArray a, RubyArray b) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((Object[]) b.getStore(), size), size);
}

@Specialization(guards = "isIntegerFixnum")
public RubyArray addEmptyIntegerFixnum(RubyArray a, RubyArray b) {
// TODO CS 5-Feb-15 hack to get things working with empty int[] store

if (a.getSize() != 0) {
throw new UnsupportedOperationException();
}

final int size = b.getSize();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.box(b.getStore()), size);
@Specialization(guards = {"!isObject", "isOtherObject"})
public RubyArray addOtherObject(RubyArray a, RubyArray b) {
final int combinedSize = a.getSize() + b.getSize();
final Object[] combined = new Object[combinedSize];
System.arraycopy(ArrayUtils.box(a.getStore()), 0, combined, 0, a.getSize());
System.arraycopy(b.getStore(), 0, combined, a.getSize(), b.getSize());
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), combined, combinedSize);
}

@Specialization(guards = "isLongFixnum")
public RubyArray addEmptyLongFixnum(RubyArray a, RubyArray b) {
// TODO CS 5-Feb-15 hack to get things working with empty long[] store

if (a.getSize() != 0) {
throw new UnsupportedOperationException();
}

final int size = b.getSize();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.box(b.getStore()), size);
@Specialization(guards = {"isObject", "!isOtherObject"})
public RubyArray addObject(RubyArray a, RubyArray b) {
final int combinedSize = a.getSize() + b.getSize();
final Object[] combined = new Object[combinedSize];
System.arraycopy(a.getStore(), 0, combined, 0, a.getSize());
System.arraycopy(ArrayUtils.box(b.getStore()), 0, combined, a.getSize(), b.getSize());
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), combined, combinedSize);
}

@Specialization(guards = "isFloat")
public RubyArray addEmptyDouble(RubyArray a, RubyArray b) {
// TODO CS 5-Feb-15 hack to get things working with empty double[] store

if (a.getSize() != 0) {
throw new UnsupportedOperationException();
}

@Specialization(guards = "isEmpty")
public RubyArray addEmpty(RubyArray a, RubyArray b) {
final int size = b.getSize();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.box(b.getStore()), size);
}

@Specialization(guards = "isObject")
public RubyArray addEmptyObject(RubyArray a, RubyArray b) {
// TODO CS 5-Feb-15 hack to get things working with empty Object[] store

if (a.getSize() != 0) {
throw new UnsupportedOperationException();
}

final int size = b.getSize();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.box(b.getStore()), size);
@Specialization(guards = "isOtherEmpty")
public RubyArray addOtherEmpty(RubyArray a, RubyArray b) {
final int size = a.getSize();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.box(a.getStore()), size);
}

}