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

Commits on Mar 19, 2015

  1. Copy the full SHA
    7d7c0fa View commit details
  2. Merge pull request #2727 from bjfish/truffle_array_concat

    [Truffle] Implementing more of Array#concat
    chrisseaton committed Mar 19, 2015
    Copy the full SHA
    1406498 View commit details
Showing with 45 additions and 23 deletions.
  1. +0 −6 spec/truffle/tags/core/array/concat_tags.txt
  2. +45 −17 truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/array/concat_tags.txt

This file was deleted.

62 changes: 45 additions & 17 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -701,38 +701,56 @@ public RubyArray concatNull(RubyArray array, RubyArray other) {
public RubyArray concatIntegerFixnum(RubyArray array, RubyArray other) {
notDesignedForCompilation();

// TODO(CS): is there already space in array?
System.arraycopy(other.getStore(), 0, array.getStore(), array.getSize(), other.getSize());
array.setStore(Arrays.copyOf((int[]) array.getStore(), array.getSize() + other.getSize()), array.getSize() + other.getSize());
final int newSize = array.getSize() + other.getSize();
int[] store = (int[]) array.getStore();

if ( store.length < newSize) {
store = Arrays.copyOf((int[]) array.getStore(), ArrayUtils.capacity(store.length, newSize));
}

System.arraycopy(other.getStore(), 0, store, array.getSize(), other.getSize());
array.setStore(store, newSize);
return array;
}

@Specialization(guards = "areBothLongFixnum")
public RubyArray concatLongFixnum(RubyArray array, RubyArray other) {
notDesignedForCompilation();

// TODO(CS): is there already space in array?
System.arraycopy(other.getStore(), 0, array.getStore(), array.getSize(), other.getSize());
array.setStore(Arrays.copyOf((long[]) array.getStore(), array.getSize() + other.getSize()), array.getSize() + other.getSize());
final int newSize = array.getSize() + other.getSize();
long[] store = (long[]) array.getStore();

if ( store.length < newSize) {
store = Arrays.copyOf((long[]) array.getStore(), ArrayUtils.capacity(store.length, newSize));
}

System.arraycopy(other.getStore(), 0, store, array.getSize(), other.getSize());
array.setStore(store, newSize);
return array;
}

@Specialization(guards = "areBothFloat")
public RubyArray concatDouble(RubyArray array, RubyArray other) {
notDesignedForCompilation();

// TODO(CS): is there already space in array?
System.arraycopy(other.getStore(), 0, array.getStore(), array.getSize(), other.getSize());
array.setStore(Arrays.copyOf((double[]) array.getStore(), array.getSize() + other.getSize()), array.getSize() + other.getSize());
final int newSize = array.getSize() + other.getSize();
double[] store = (double[]) array.getStore();

if ( store.length < newSize) {
store = Arrays.copyOf((double[]) array.getStore(), ArrayUtils.capacity(store.length, newSize));
}

System.arraycopy(other.getStore(), 0, store, array.getSize(), other.getSize());
array.setStore(store, newSize);
return array;
}

@Specialization(guards = "areBothObject")
public RubyArray concatObject(RubyArray array, RubyArray other) {
notDesignedForCompilation();

int size = array.getSize();
int newSize = size + other.getSize();
final int size = array.getSize();
final int newSize = size + other.getSize();
Object[] store = (Object[]) array.getStore();

if (newSize > store.length) {
@@ -748,12 +766,22 @@ public RubyArray concatObject(RubyArray array, RubyArray other) {
public RubyArray concat(RubyArray array, RubyArray other) {
notDesignedForCompilation();

// TODO(CS): is there already space in array?
// TODO(CS): if array is Object[], use Arrays.copyOf
final Object[] newStore = new Object[array.getSize() + other.getSize()];
ArrayUtils.copy(array.getStore(), newStore, 0, array.getSize());
ArrayUtils.copy(other.getStore(), newStore, array.getSize(), other.getSize());
array.setStore(newStore, array.getSize() + other.getSize());
final int newSize = array.getSize() + other.getSize();

Object[] store;
if (array.getStore() instanceof Object[]) {
store = (Object[]) array.getStore();
if (store.length < newSize) {
store = Arrays.copyOf(store, ArrayUtils.capacity(store.length, newSize));
}
ArrayUtils.copy(other.getStore(), store, array.getSize(), other.getSize());
} else {
store = new Object[newSize];
ArrayUtils.copy(array.getStore(), store, 0, array.getSize());
ArrayUtils.copy(other.getStore(), store, array.getSize(), other.getSize());
}

array.setStore(store, newSize);
return array;
}