Skip to content

Commit

Permalink
[Truffle] Fix appending an Object[] to an int[] in the array builder -
Browse files Browse the repository at this point in the history
…fixes #2769.
  • Loading branch information
chrisseaton committed Mar 28, 2015
1 parent 53683ba commit 9e423f9
Showing 1 changed file with 6 additions and 12 deletions.
Expand Up @@ -146,7 +146,6 @@ public static class IntegerArrayBuilderNode extends ArrayBuilderNode {
private final int expectedLength;

@CompilerDirectives.CompilationFinal private boolean hasAppendedIntegerArray = false;
@CompilerDirectives.CompilationFinal private boolean hasAppendedObjectArray = false;

public IntegerArrayBuilderNode(RubyContext context, int expectedLength) {
super(context);
Expand Down Expand Up @@ -200,11 +199,6 @@ public Object append(Object store, int index, RubyArray array) {
return store;
}

if (hasAppendedObjectArray && otherStore instanceof Object[]) {
System.arraycopy(otherStore, 0, store, index, array.getSize());
return store;
}

CompilerDirectives.transferToInterpreterAndInvalidate();

if (otherStore instanceof int[]) {
Expand All @@ -213,13 +207,13 @@ public Object append(Object store, int index, RubyArray array) {
return store;
}

if (otherStore instanceof Object[]) {
hasAppendedObjectArray = true;
System.arraycopy(otherStore, 0, store, index, array.getSize());
return store;
}
CompilerDirectives.transferToInterpreter();

throw new UnsupportedOperationException(array.getStore().getClass().getName());
replace(new ObjectArrayBuilderNode(getContext(), expectedLength));
final Object[] newStore = ArrayUtils.box((int[]) store);
System.arraycopy(otherStore, 0, newStore, index, array.getSize());

return newStore;
}

@Override
Expand Down

0 comments on commit 9e423f9

Please sign in to comment.