Skip to content

Commit

Permalink
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -523,6 +523,27 @@ public Object setObject(DynamicObject array, int start, int length, Object value
}
}

@Specialization(guards = {
"isRubyArray(replacement)",
"isIntArray(replacement)",
"length >= 0",
"length == getArraySize(replacement)"
})
public Object setOtherIntArraySameLength(DynamicObject array, int start, int length, DynamicObject replacement,
@Cached("createBinaryProfile()") ConditionProfile negativeIndexProfile) {
final int normalizedIndex = ArrayOperations.normalizeIndex(getSize(array), start, negativeIndexProfile);
if (normalizedIndex < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreLibrary().indexTooSmallError("array", start, getSize(array), this));
}

final int[] replacementStore = (int[]) getStore(replacement);
for (int i = 0; i < length; i++) {
write(array, normalizedIndex + i, replacementStore[i]);
}
return replacement;
}

@Specialization(guards = { "!isInteger(startObject)", "!isInteger(lengthObject) || isRubyArray(value)" })
public Object setOtherArray(VirtualFrame frame, DynamicObject array, Object startObject, Object lengthObject, DynamicObject value,
@Cached("createBinaryProfile()") ConditionProfile negativeIndexProfile) {
@@ -666,6 +687,10 @@ public Object setIntegerFixnumRange(DynamicObject array, DynamicObject range, Dy
return other;
}

protected int getArraySize(DynamicObject array) {
return getSize(array);
}

private Object write(DynamicObject array, int index, Object value) {
if (writeNode == null) {
CompilerDirectives.transferToInterpreter();

0 comments on commit a4c91d7

Please sign in to comment.