package com.oracle.truffle.js.runtime.array.dyn;
import static com.oracle.truffle.js.runtime.builtins.JSAbstractArray.arrayGetArrayOffset;
import static com.oracle.truffle.js.runtime.builtins.JSAbstractArray.arrayGetIndexOffset;
import static com.oracle.truffle.js.runtime.builtins.JSAbstractArray.arraySetArrayOffset;
import static com.oracle.truffle.js.runtime.builtins.JSAbstractArray.arraySetIndexOffset;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.js.runtime.JSConfig;
import com.oracle.truffle.js.runtime.array.ScriptArray;
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
public abstract class AbstractContiguousJSObjectArray extends AbstractJSObjectArray {
protected AbstractContiguousJSObjectArray(int integrityLevel, DynamicArrayCache cache) {
super(integrityLevel, cache);
}
@Override
public DynamicObject getInBoundsFastJSObject(DynamicObject object, int index) {
return castNonNull(getArray(object)[(int) (index - getIndexOffset(object))]);
}
@Override
public void setInBoundsFast(DynamicObject object, int index, JSDynamicObject value) {
getArray(object)[(int) (index - getIndexOffset(object))] = checkNonNull(value);
if (JSConfig.TraceArrayWrites) {
traceWriteValue("InBoundsFast", index, value);
}
}
@Override
protected final void setLengthLess(DynamicObject object, long length, ProfileHolder profile) {
setLengthLessContiguous(object, length, profile);
}
@Override
protected final int prepareInBoundsFast(DynamicObject object, long index) {
return (int) (index - getIndexOffset(object));
}
@Override
protected final void setArrayOffset(DynamicObject object, int arrayOffset) {
arraySetArrayOffset(object, arrayOffset);
}
@Override
protected final int getArrayOffset(DynamicObject object) {
return arrayGetArrayOffset(object);
}
@Override
protected final void setIndexOffset(DynamicObject object, long indexOffset) {
arraySetIndexOffset(object, indexOffset);
}
@Override
protected final long getIndexOffset(DynamicObject object) {
return arrayGetIndexOffset(object);
}
@Override
public final long firstElementIndex(DynamicObject object) {
return getIndexOffset(object) + getArrayOffset(object);
}
@Override
public final long lastElementIndex(DynamicObject object) {
return getIndexOffset(object) + getArrayOffset(object) + getUsedLength(object) - 1;
}
@Override
public boolean hasHoles(DynamicObject object) {
return true;
}
@Override
public ScriptArray addRangeImpl(DynamicObject object, long offset, int size) {
return addRangeImplContiguous(object, offset, size);
}
}