Skip to content

Commit

Permalink
[Truffle] Implement missing cases in ObjectArrayBuilderNode#appendArr…
Browse files Browse the repository at this point in the history
…ay().
  • Loading branch information
eregon committed Nov 16, 2016
1 parent 4e72110 commit 629256e
Showing 1 changed file with 26 additions and 3 deletions.
Expand Up @@ -227,7 +227,6 @@ public Object appendArray(Object store, int index, DynamicObject array) {

@Override
public Object appendValue(Object store, int index, Object value) {
// TODO(CS): inject probability
if (store instanceof int[] && value instanceof Integer) {
((int[]) store)[index] = (int) value;
return store;
Expand Down Expand Up @@ -296,7 +295,6 @@ public Object appendArray(Object store, int index, DynamicObject array) {

@Override
public Object appendValue(Object store, int index, Object value) {
// TODO(CS): inject probability
if (store instanceof long[]) {
if (value instanceof Long) {
((long[]) store)[index] = (long) value;
Expand Down Expand Up @@ -376,7 +374,6 @@ public Object appendArray(Object store, int index, DynamicObject array) {

@Override
public Object appendValue(Object store, int index, Object value) {
// TODO(CS): inject probability
if (store instanceof double[] && value instanceof Double) {
((double[]) store)[index] = (double) value;
return store;
Expand All @@ -399,6 +396,8 @@ private static class ObjectArrayBuilderNode extends ArrayBuilderNode {

@CompilationFinal private boolean hasAppendedObjectArray = false;
@CompilationFinal private boolean hasAppendedIntArray = false;
@CompilationFinal private boolean hasAppendedLongArray = false;
@CompilationFinal private boolean hasAppendedDoubleArray = false;

public ObjectArrayBuilderNode(RubyContext context, int expectedLength) {
super(context);
Expand Down Expand Up @@ -458,6 +457,28 @@ public Object appendArray(Object store, int index, DynamicObject array) {
return store;
}

if (hasAppendedLongArray && otherStore instanceof long[]) {
final Object[] objectStore = (Object[]) store;
final long[] otherLongStore = (long[]) otherStore;

for (int n = 0; n < Layouts.ARRAY.getSize(array); n++) {
objectStore[index + n] = otherLongStore[n];
}

return store;
}

if (hasAppendedDoubleArray && otherStore instanceof double[]) {
final Object[] objectStore = (Object[]) store;
final double[] otherDoubleStore = (double[]) otherStore;

for (int n = 0; n < Layouts.ARRAY.getSize(array); n++) {
objectStore[index + n] = otherDoubleStore[n];
}

return store;
}

CompilerDirectives.transferToInterpreterAndInvalidate();

if (otherStore instanceof int[]) {
Expand All @@ -470,6 +491,7 @@ public Object appendArray(Object store, int index, DynamicObject array) {
}

if (otherStore instanceof long[]) {
hasAppendedLongArray = true;
for (int n = 0; n < Layouts.ARRAY.getSize(array); n++) {
((Object[]) store)[index + n] = ((long[]) otherStore)[n];
}
Expand All @@ -478,6 +500,7 @@ public Object appendArray(Object store, int index, DynamicObject array) {
}

if (otherStore instanceof double[]) {
hasAppendedDoubleArray = true;
for (int n = 0; n < Layouts.ARRAY.getSize(array); n++) {
((Object[]) store)[index + n] = ((double[]) otherStore)[n];
}
Expand Down

0 comments on commit 629256e

Please sign in to comment.