final Object arg = args[0];
if (arg instanceof RubyArray) {
singleArray.enter();
final RubyArray array = (RubyArray) arg;
if (array.getStore() instanceof Object[]) {
objectArray.enter();
final Object[] store = (Object[]) array.getStore();
// TODO(CS): zero length arrays might be a good specialisation
if (store.length <= RubyHash.HASHES_SMALL) {
smallObjectArray.enter();
final int size = store.length;
final Object[] newStore = new Object[RubyHash.HASHES_SMALL * 2];
for (int n = 0; n < RubyHash.HASHES_SMALL; n++) {
if (n < size) {
final Object pair = store[n];
if (!(pair instanceof RubyArray)) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException();
}
final RubyArray pairArray = (RubyArray) pair;
if (!(pairArray.getStore() instanceof Object[])) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException();
}
final Object[] pairStore = (Object[]) pairArray.getStore();
newStore[n * 2] = pairStore[0];
newStore[n * 2 + 1] = pairStore[1];
}
}