Skip to content

Commit

Permalink
Showing 7 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ public DynamicObject executeDynamicObject(VirtualFrame frame) throws UnexpectedR
public Object[] executeObjectArray(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

if (value instanceof Object[]) {
if (value.getClass() == Object[].class) {
return (Object[]) value;
} else {
throw new UnexpectedResultException(value);
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ protected Object appendValueFallback(Object store, int index, Object value, int
// The store type cannot be assumed if multiple threads use the same builder,
// so just use the generic box() since anyway this is slow path.
final Object[] newStore;
if (store instanceof Object[]) {
if (store.getClass() == Object[].class) {
newStore = (Object[]) store;
} else {
newStore = ArrayUtils.box(store);
@@ -445,7 +445,7 @@ public Object appendArray(Object store, int index, DynamicObject array) {
return store;
}

if (hasAppendedObjectArray && otherStore instanceof Object[]) {
if (hasAppendedObjectArray && otherStore.getClass() == Object[].class) {
System.arraycopy(otherStore, 0, store, index, Layouts.ARRAY.getSize(array));
return store;
}
@@ -488,7 +488,7 @@ public Object appendArray(Object store, int index, DynamicObject array) {
return store;
}

if (otherStore instanceof Object[]) {
if (otherStore.getClass() == Object[].class) {
hasAppendedObjectArray = true;
System.arraycopy(otherStore, 0, store, index, Layouts.ARRAY.getSize(array));
return store;
Original file line number Diff line number Diff line change
@@ -96,19 +96,20 @@ public Object construct(VirtualFrame frame, DynamicObject hashClass, Object[] ar
}

final DynamicObject pairArray = (DynamicObject) pair;
final Object pairStore = Layouts.ARRAY.getStore(pairArray);

if (!(Layouts.ARRAY.getStore(pairArray) instanceof Object[])) {
if (pairStore != null && pairStore.getClass() != Object[].class) {
return constructFallback(frame, hashClass, args);
}

if (Layouts.ARRAY.getSize(pairArray) != 2) {
return constructFallback(frame, hashClass, args);
}

final Object[] pairStore = (Object[]) Layouts.ARRAY.getStore(pairArray);
final Object[] pairObjectStore = (Object[]) pairStore;

final Object key = pairStore[0];
final Object value = pairStore[1];
final Object key = pairObjectStore[0];
final Object value = pairObjectStore[1];

final int hashed = hashNode.hash(frame, key);

@@ -136,14 +137,15 @@ public boolean isSmallArrayOfPairs(Object[] args) {
}

final DynamicObject array = (DynamicObject) arg;
final Object store = Layouts.ARRAY.getStore(array);

if (!(Layouts.ARRAY.getStore(array) instanceof Object[])) {
if (store != null && store.getClass() != Object[].class) {
return false;
}

final Object[] store = (Object[]) Layouts.ARRAY.getStore(array);
final Object[] objectStore = (Object[]) store;

if (store.length > getContext().getOptions().HASH_PACKED_ARRAY_MAX) {
if (objectStore.length > getContext().getOptions().HASH_PACKED_ARRAY_MAX) {
return false;
}

Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ private Object[] splat(Object argument) {
return ArrayUtils.boxUntil((long[]) store, size);
} else if (seenFloatInUnsplat && store instanceof double[]) {
return ArrayUtils.boxUntil((double[]) store, size);
} else if (seenObjectInUnsplat && store instanceof Object[]) {
} else if (seenObjectInUnsplat && store != null && store.getClass() == Object[].class) {
return ArrayUtils.extractRange((Object[]) store, 0, size);
}

@@ -224,7 +224,7 @@ private Object[] splat(Object argument) {
} else if (store instanceof double[]) {
seenFloatInUnsplat = true;
return ArrayUtils.boxUntil((double[]) store, size);
} else if (store instanceof Object[]) {
} else if (store.getClass() == Object[].class) {
seenObjectInUnsplat = true;
return ArrayUtils.extractRange((Object[]) store, 0, size);
}
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public static ArrayMirror reflect(Object array) {
return reflect((long[]) array);
} else if (array instanceof double[]) {
return reflect((double[]) array);
} else if (array instanceof Object[]) {
} else if (array.getClass() == Object[].class) {
return reflect((Object[]) array);
} else {
throw new UnsupportedOperationException();
Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@ public static Object[] boxExtra(Object array, int extra) {
return boxExtra((long[]) array, extra);
} else if (array instanceof double[]) {
return boxExtra((double[]) array, extra);
} else if (array instanceof Object[]) {
} else if (array.getClass() == Object[].class) {
final Object[] objectArray = (Object[]) array;
return ArrayUtils.grow(objectArray, objectArray.length + extra);
} else {
@@ -260,7 +260,7 @@ public static Object[] boxUntil(Object array, int length) {
return boxUntil((long[]) array, length);
} else if (array instanceof double[]) {
return boxUntil((double[]) array, length);
} else if (array instanceof Object[]) {
} else if (array.getClass() == Object[].class) {
final Object[] objectArray = (Object[]) array;
return Arrays.copyOf(objectArray, length);
} else {
@@ -333,7 +333,7 @@ public static void copy(Object source, Object[] destination, int destinationStar
for (int n = 0; n < length; n++) {
destination[destinationStart + n] = unboxedSource[n];
}
} else if (source instanceof Object[]) {
} else if (source.getClass() == Object[].class) {
arraycopy((Object[]) source, 0, destination, destinationStart, length);
} else {
throw new UnsupportedOperationException();
Original file line number Diff line number Diff line change
@@ -27,15 +27,13 @@ public static boolean verifyStore(RubyContext context, DynamicObject hash) {
}

public static boolean verifyStore(RubyContext context, Object store, int size, Entry firstInSequence, Entry lastInSequence) {
assert store == null || store instanceof Object[] || store instanceof Entry[];
assert store == null || store.getClass() == Object[].class || store instanceof Entry[];

if (store == null) {
assert size == 0;
assert firstInSequence == null;
assert lastInSequence == null;
}

if (store instanceof Entry[]) {
} else if (store instanceof Entry[]) {
assert lastInSequence == null || lastInSequence.getNextInSequence() == null;

final Entry[] entryStore = (Entry[]) store;
@@ -86,7 +84,7 @@ public static boolean verifyStore(RubyContext context, Object store, int size, E
}

assert foundSizeSequence == size : String.format("%d %d", foundSizeSequence, size);
} else if (store instanceof Object[]) {
} else if (store.getClass() == Object[].class) {
assert ((Object[]) store).length == context.getOptions().HASH_PACKED_ARRAY_MAX * PackedArrayStrategy.ELEMENTS_PER_ENTRY : ((Object[]) store).length;

final Object[] packedStore = (Object[]) store;

0 comments on commit d874349

Please sign in to comment.