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;
public abstract class AbstractContiguousIntArray extends AbstractIntArray {
protected AbstractContiguousIntArray(int integrityLevel, DynamicArrayCache cache) {
super(integrityLevel, cache);
}
@Override
public int getInBoundsFastInt(DynamicObject object, int index) {
return getArray(object)[(int) (index - getIndexOffset(object))];
}
@Override
public void setInBoundsFast(DynamicObject object, int index, int value) {
getArray(object)[(int) (index - getIndexOffset(object))] = 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);
}
}