8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this

Reviewed-by: attila, hannesw
This commit is contained in:
Marcus Lagergren 2014-09-26 18:47:20 +02:00
parent 50228a4342
commit 3d2c518ad8
30 changed files with 213 additions and 218 deletions

View File

@ -29,8 +29,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import jdk.nashorn.api.scripting.AbstractJSObject;
import java.nio.DoubleBuffer;
import jdk.nashorn.api.scripting.AbstractJSObject;
/**
* Simple class demonstrating pluggable script object
@ -112,6 +112,8 @@ public class BufferArray extends AbstractJSObject {
return true;
}
};
default:
break;
}
return null;
}

View File

@ -27,7 +27,6 @@ package jdk.nashorn.internal.codegen;
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS_VAR;
import static jdk.nashorn.internal.codegen.CompilerConstants.EXPLODED_ARGUMENT_PREFIX;
import java.lang.invoke.MethodType;
import java.util.ArrayDeque;
import java.util.ArrayList;
@ -35,7 +34,6 @@ import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import jdk.nashorn.internal.ir.AccessNode;
import jdk.nashorn.internal.ir.CallNode;
import jdk.nashorn.internal.ir.Expression;
@ -131,7 +129,7 @@ public final class ApplySpecialization extends NodeVisitor<LexicalContext> imple
@SuppressWarnings("serial")
final UnsupportedOperationException uoe = new UnsupportedOperationException() {
@Override
public Throwable fillInStackTrace() {
public synchronized Throwable fillInStackTrace() {
return null;
}
};

View File

@ -38,7 +38,6 @@ import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.SCOPE_DEPTHS
import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.SPLIT;
import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.SYMBOLS_ASSIGNED;
import static jdk.nashorn.internal.runtime.logging.DebugLogger.quote;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.EnumSet;
@ -48,7 +47,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import jdk.nashorn.internal.AssertsEnabled;
import jdk.nashorn.internal.codegen.Compiler.CompilationPhases;
import jdk.nashorn.internal.ir.FunctionNode;
@ -627,7 +625,7 @@ enum CompilationPhase {
/**
* Start a compilation phase
* @param compiler
* @param compiler the compiler to use
* @param functionNode function to compile
* @return function node
*/

View File

@ -2134,6 +2134,8 @@ public class MethodEmitter implements Emitter {
load("Function");
invoke(ScriptRuntime.INVALIDATE_RESERVED_BUILTIN_NAME);
break;
default:
break;
}
return this;
}

View File

@ -443,7 +443,7 @@ public final class OptimisticTypesPersistence {
// does not increase filesDeleted
}
files[i] = null; // gc eligible
};
}
}
private static Path[] getAllRegularFilesInLastModifiedOrder() throws IOException {
@ -454,7 +454,7 @@ public final class OptimisticTypesPersistence {
@Override
public boolean test(final Path path) {
return !Files.isDirectory(path);
};
}
})
.map(new Function<Path, PathAndTime>() {
@Override

View File

@ -47,7 +47,6 @@ import static jdk.internal.org.objectweb.asm.Opcodes.T_DOUBLE;
import static jdk.internal.org.objectweb.asm.Opcodes.T_INT;
import static jdk.internal.org.objectweb.asm.Opcodes.T_LONG;
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -299,7 +298,7 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
*
* @param typeMap the type map
* @param output data output
* @throws IOException
* @throws IOException if write cannot be completed
*/
public static void writeTypeMap(final Map<Integer, Type> typeMap, final DataOutput output) throws IOException {
if (typeMap == null) {
@ -329,7 +328,7 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
*
* @param input data input
* @return type map
* @throws IOException
* @throws IOException if read cannot be completed
*/
public static Map<Integer, Type> readTypeMap(final DataInput input) throws IOException {
final int size = input.readInt();

View File

@ -561,6 +561,7 @@ public final class Global extends ScriptObject implements Scope {
*
* @param engine ScriptEngine to initialize
*/
@SuppressWarnings("hiding")
public void initBuiltinObjects(final ScriptEngine engine) {
if (this.builtinObject != null) {
// already initialized, just return
@ -905,10 +906,12 @@ public final class Global extends ScriptObject implements Scope {
}
switch (nameStr) {
case "context":
return sctxt;
case "engine":
return global.engine;
case "context":
return sctxt;
case "engine":
return global.engine;
default:
break;
}
if (self == UNDEFINED) {
@ -1715,6 +1718,7 @@ public final class Global extends ScriptObject implements Scope {
return func;
}
@SuppressWarnings("hiding")
private void init(final ScriptEngine engine) {
assert Context.getGlobal() == this : "this global is not set as current";

View File

@ -1835,7 +1835,7 @@ public final class NativeArray extends ScriptObject implements OptimisticBuiltin
return false;
}
private ContinuousArrayData getContinuousNonEmptyArrayData(final Object self) {
private static ContinuousArrayData getContinuousNonEmptyArrayData(final Object self) {
final ContinuousArrayData data = getContinuousArrayData(self);
if (data != null) {
return data.length() == 0 ? null : data;

View File

@ -26,7 +26,6 @@
package jdk.nashorn.internal.objects;
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Objects;
@ -262,8 +261,8 @@ public final class NativeDebug extends ScriptObject {
/**
* Set the event queue capacity
* @param self
* @param newCapacity
* @param self an event queue
* @param newCapacity new capacity
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void setEventQueueCapacity(final Object self, final Object newCapacity) {

View File

@ -77,7 +77,7 @@ public @interface SpecializedFunction {
public boolean isEmpty() {
return true;
}
};
}
/**
* Get the class representing the empty link logic

View File

@ -210,7 +210,7 @@ public abstract class CodeStore implements Loggable {
/**
* Constructor
*
* @throws IOException
* @throws IOException if there are read/write problems with the cache and cache directory
*/
public DirectoryCodeStore() throws IOException {
this(Options.getStringProperty("nashorn.persistent.code.cache", "nashorn_code_cache"), false, DEFAULT_MIN_SIZE);
@ -222,7 +222,7 @@ public abstract class CodeStore implements Loggable {
* @param path directory to store code in
* @param readOnly is this a read only code store
* @param minSize minimum file size for caching scripts
* @throws IOException
* @throws IOException if there are read/write problems with the cache and cache directory
*/
public DirectoryCodeStore(final String path, final boolean readOnly, final int minSize) throws IOException {
this.dir = checkDirectory(path, readOnly);

View File

@ -110,9 +110,8 @@ final class CompiledFunction {
*/
this.invoker = MH.insertArguments(invoker, invoker.type().parameterCount() - 1, UnwarrantedOptimismException.FIRST_PROGRAM_POINT);
throw new AssertionError("Optimistic (UnwarrantedOptimismException throwing) builtin functions are currently not in use");
} else {
this.invoker = invoker;
}
this.invoker = invoker;
this.constructor = constructor;
this.flags = flags;
this.callSiteType = callSiteType;
@ -510,8 +509,8 @@ final class CompiledFunction {
return ((ArrayType)paramTypes[paramTypes.length - 1]).getElementType();
}
boolean matchesCallSite(final MethodType callSiteType, final boolean pickVarArg) {
if (callSiteType.equals(this.callSiteType)) {
boolean matchesCallSite(final MethodType other, final boolean pickVarArg) {
if (other.equals(this.callSiteType)) {
return true;
}
final MethodType type = type();
@ -521,7 +520,7 @@ final class CompiledFunction {
return pickVarArg;
}
final int csParamCount = getParamCount(callSiteType);
final int csParamCount = getParamCount(other);
final boolean csIsVarArg = csParamCount == Integer.MAX_VALUE;
final int thisThisIndex = needsCallee() ? 1 : 0; // Index of "this" parameter in this function's type
@ -530,7 +529,7 @@ final class CompiledFunction {
// We must match all incoming parameters, except "this". Starting from 1 to skip "this".
for(int i = 1; i < minParams; ++i) {
final Type fnType = Type.typeFor(type.parameterType(i + thisThisIndex));
final Type csType = csIsVarArg ? Type.OBJECT : Type.typeFor(callSiteType.parameterType(i + 1));
final Type csType = csIsVarArg ? Type.OBJECT : Type.typeFor(other.parameterType(i + 1));
if(!fnType.isEquivalentTo(csType)) {
return false;
}
@ -752,9 +751,9 @@ final class CompiledFunction {
return sb.toString();
}
private void logRecompile(final String reason, final FunctionNode fn, final MethodType callSiteType, final Map<Integer, Type> ipp) {
private void logRecompile(final String reason, final FunctionNode fn, final MethodType type, final Map<Integer, Type> ipp) {
if (log.isEnabled()) {
log.info(reason, DebugLogger.quote(fn.getName()), " signature: ", callSiteType, " ", toStringInvalidations(ipp));
log.info(reason, DebugLogger.quote(fn.getName()), " signature: ", type, " ", toStringInvalidations(ipp));
}
}

View File

@ -33,7 +33,6 @@ import static jdk.nashorn.internal.runtime.CodeStore.newCodeStore;
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import static jdk.nashorn.internal.runtime.Source.sourceFor;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@ -64,9 +63,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
import javax.script.ScriptEngine;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.util.CheckClassAdapter;
import jdk.nashorn.api.scripting.ClassFilter;
@ -1390,7 +1387,7 @@ public final class Context {
* logic to e.g. multiple switchpoint classes.
*/
public static final class BuiltinSwitchPoint extends SwitchPoint {
//empty
}
/**

View File

@ -26,7 +26,6 @@
package jdk.nashorn.internal.runtime;
import static jdk.nashorn.internal.parser.TokenType.EOF;
import jdk.nashorn.internal.parser.Lexer;
import jdk.nashorn.internal.parser.Token;
import jdk.nashorn.internal.parser.TokenStream;
@ -42,12 +41,12 @@ public final class Debug {
/**
* Return the topmost JavaScript frame in a stack trace
* @param e
* @param t throwable that contains the stack trace
* @return line describing the topmost JavaScript frame
*/
public static String firstJSFrame(final Throwable e) {
for (final StackTraceElement ste : e.getStackTrace()) {
if(ECMAErrors.isScriptFrame(ste)) {
public static String firstJSFrame(final Throwable t) {
for (final StackTraceElement ste : t.getStackTrace()) {
if (ECMAErrors.isScriptFrame(ste)) {
return ste.toString();
}
}

View File

@ -501,13 +501,13 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) {
final String className = entry.getKey();
final byte[] code = entry.getValue();
final byte[] bytecode = entry.getValue();
if (className.equals(mainClassName)) {
continue;
}
installedClasses.put(className, installer.install(className, code));
installedClasses.put(className, installer.install(className, bytecode));
}
final Map<Integer, FunctionInitializer> initializers = script.getInitializers();
@ -588,9 +588,9 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
return lookupCodeMethod(fn.getCompileUnit().getCode(), type);
}
MethodHandle lookupCodeMethod(final Class<?> code, final MethodType targetType) {
MethodHandle lookupCodeMethod(final Class<?> codeClass, final MethodType targetType) {
log.info("Looking up ", DebugLogger.quote(name), " type=", targetType);
return MH.findStatic(LOOKUP, code, functionName, targetType);
return MH.findStatic(LOOKUP, codeClass, functionName, targetType);
}
/**

View File

@ -501,7 +501,7 @@ public abstract class ScriptFunction extends ScriptObject {
* @param linkLogicClass linkLogicClass, or null if no link logic exists
* @return link logic instance, or null if one could not be constructed for this receiver
*/
private LinkLogic getLinkLogic(final Object self, final Class<? extends LinkLogic> linkLogicClass) {
private static LinkLogic getLinkLogic(final Object self, final Class<? extends LinkLogic> linkLogicClass) {
if (linkLogicClass == null) {
return LinkLogic.EMPTY_INSTANCE; //always OK to link this, specialization but without special linking logic
}

View File

@ -935,10 +935,10 @@ public abstract class ScriptObject implements PropertyAccess {
* creating setters that probably aren't used. Inject directly into the spill pool
* the defaults for "arguments" and "caller"
*
* @param key
* @param propertyFlags
* @param getter
* @param setter
* @param key property key
* @param propertyFlags flags
* @param getter getter for {@link UserAccessorProperty}, null if not present or N/A
* @param setter setter for {@link UserAccessorProperty}, null if not present or N/A
*/
protected final void initUserAccessors(final String key, final int propertyFlags, final ScriptFunction getter, final ScriptFunction setter) {
final int slot = spillLength;
@ -1749,8 +1749,8 @@ public abstract class ScriptObject implements PropertyAccess {
*/
public Object put(final Object key, final Object value, final boolean strict) {
final Object oldValue = get(key);
final int flags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
set(key, value, flags);
final int scriptObjectFlags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
set(key, value, scriptObjectFlags);
return oldValue;
}
@ -1763,9 +1763,9 @@ public abstract class ScriptObject implements PropertyAccess {
* @param strict strict mode or not
*/
public void putAll(final Map<?, ?> otherMap, final boolean strict) {
final int flags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
final int scriptObjectFlags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
for (final Map.Entry<?, ?> entry : otherMap.entrySet()) {
set(entry.getKey(), entry.getValue(), flags);
set(entry.getKey(), entry.getValue(), scriptObjectFlags);
}
}
@ -2046,7 +2046,7 @@ public abstract class ScriptObject implements PropertyAccess {
// Marks a property as declared and sets its value. Used as slow path for block-scoped LET and CONST
@SuppressWarnings("unused")
private void declareAndSet(final String key, final Object value) {
final PropertyMap map = getMap();
final PropertyMap oldMap = getMap();
final FindProperty find = findProperty(key, false);
assert find != null;
@ -2054,7 +2054,7 @@ public abstract class ScriptObject implements PropertyAccess {
assert property != null;
assert property.needsDeclaration();
final PropertyMap newMap = map.replaceProperty(property, property.removeFlags(Property.NEEDS_DECLARATION));
final PropertyMap newMap = oldMap.replaceProperty(property, property.removeFlags(Property.NEEDS_DECLARATION));
setMap(newMap);
set(key, value, 0);
}

View File

@ -536,7 +536,7 @@ public abstract class ArrayData {
final Class<?> widest = widestType(items);
ArrayData newData = convert(widest);
long pos = newData.length();
long pos = newData.length;
for (final Object item : items) {
newData = newData.ensure(pos); //avoid sparse array
newData.set((int)pos++, item, strict);

View File

@ -39,7 +39,7 @@ abstract class ArrayFilter extends ArrayData {
protected ArrayData underlying;
ArrayFilter(final ArrayData underlying) {
super(underlying.length());
super(underlying.length);
this.underlying = underlying;
}
@ -70,13 +70,13 @@ abstract class ArrayFilter extends ArrayData {
@Override
public void shiftLeft(final int by) {
underlying.shiftLeft(by);
setLength(underlying.length());
setLength(underlying.length);
}
@Override
public ArrayData shiftRight(final int by) {
underlying = underlying.shiftRight(by);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@ -84,7 +84,7 @@ abstract class ArrayFilter extends ArrayData {
@Override
public ArrayData ensure(final long safeIndex) {
underlying = underlying.ensure(safeIndex);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@ -92,7 +92,7 @@ abstract class ArrayFilter extends ArrayData {
@Override
public ArrayData shrink(final long newLength) {
underlying = underlying.shrink(newLength);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@ -100,7 +100,7 @@ abstract class ArrayFilter extends ArrayData {
@Override
public ArrayData set(final int index, final Object value, final boolean strict) {
underlying = underlying.set(index, value, strict);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@ -108,7 +108,7 @@ abstract class ArrayFilter extends ArrayData {
@Override
public ArrayData set(final int index, final int value, final boolean strict) {
underlying = underlying.set(index, value, strict);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@ -116,7 +116,7 @@ abstract class ArrayFilter extends ArrayData {
@Override
public ArrayData set(final int index, final long value, final boolean strict) {
underlying = underlying.set(index, value, strict);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@ -124,7 +124,7 @@ abstract class ArrayFilter extends ArrayData {
@Override
public ArrayData set(final int index, final double value, final boolean strict) {
underlying = underlying.set(index, value, strict);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@ -189,28 +189,28 @@ abstract class ArrayFilter extends ArrayData {
@Override
public ArrayData delete(final int index) {
underlying = underlying.delete(index);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@Override
public ArrayData delete(final long from, final long to) {
underlying = underlying.delete(from, to);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@Override
public ArrayData convert(final Class<?> type) {
underlying = underlying.convert(type);
setLength(underlying.length());
setLength(underlying.length);
return this;
}
@Override
public Object pop() {
final Object value = underlying.pop();
setLength(underlying.length());
setLength(underlying.length);
return value;
}

View File

@ -76,11 +76,11 @@ public abstract class ContinuousArrayData extends ArrayData {
* array without reallocating, or if we are overwriting an already
* allocated element
*
* @param index
* @param index index to check
* @return true if we don't need to do any array reallocation to fit an element at index
*/
public final boolean hasRoomFor(final int index) {
return has(index) || (index == length() && ensure(index) == this);
return has(index) || (index == length && ensure(index) == this);
}
/**

View File

@ -26,7 +26,6 @@
package jdk.nashorn.internal.runtime.arrays;
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import java.lang.reflect.Array;
import jdk.nashorn.internal.runtime.BitVector;
@ -40,7 +39,7 @@ final class DeletedArrayFilter extends ArrayFilter {
DeletedArrayFilter(final ArrayData underlying) {
super(underlying);
this.deleted = new BitVector(underlying.length());
this.deleted = new BitVector(underlying.length);
}
@Override
@ -80,25 +79,25 @@ final class DeletedArrayFilter extends ArrayFilter {
@Override
public void shiftLeft(final int by) {
super.shiftLeft(by);
deleted.shiftLeft(by, length());
deleted.shiftLeft(by, length);
}
@Override
public ArrayData shiftRight(final int by) {
super.shiftRight(by);
deleted.shiftRight(by, length());
deleted.shiftRight(by, length);
return this;
}
@Override
public ArrayData ensure(final long safeIndex) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH && safeIndex >= length()) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH && safeIndex >= length) {
return new SparseArrayData(this, safeIndex + 1);
}
super.ensure(safeIndex);
deleted.resize(length());
deleted.resize(length);
return this;
}
@ -106,7 +105,7 @@ final class DeletedArrayFilter extends ArrayFilter {
@Override
public ArrayData shrink(final long newLength) {
super.shrink(newLength);
deleted.resize(length());
deleted.resize(length);
return this;
}
@ -147,7 +146,7 @@ final class DeletedArrayFilter extends ArrayFilter {
@Override
public ArrayData delete(final int index) {
final long longIndex = ArrayIndex.toLongIndex(index);
assert longIndex >= 0 && longIndex < length();
assert longIndex >= 0 && longIndex < length;
deleted.set(longIndex);
underlying.setEmpty(index);
return this;
@ -155,7 +154,7 @@ final class DeletedArrayFilter extends ArrayFilter {
@Override
public ArrayData delete(final long fromIndex, final long toIndex) {
assert fromIndex >= 0 && fromIndex <= toIndex && toIndex < length();
assert fromIndex >= 0 && fromIndex <= toIndex && toIndex < length;
deleted.setRange(fromIndex, toIndex + 1);
underlying.setEmpty(fromIndex, toIndex);
return this;
@ -163,7 +162,7 @@ final class DeletedArrayFilter extends ArrayFilter {
@Override
public Object pop() {
final long index = length() - 1;
final long index = length - 1;
if (super.has((int)index)) {
final boolean isDeleted = deleted.isSet(index);
@ -180,7 +179,7 @@ final class DeletedArrayFilter extends ArrayFilter {
final ArrayData newArray = underlying.slice(from, to);
final DeletedArrayFilter newFilter = new DeletedArrayFilter(newArray);
newFilter.getDeleted().copy(deleted);
newFilter.getDeleted().shiftLeft(from, newFilter.length());
newFilter.getDeleted().shiftLeft(from, newFilter.length);
return newFilter;
}

View File

@ -45,7 +45,7 @@ final class DeletedRangeArrayFilter extends ArrayFilter {
if(hi < SparseArrayData.MAX_DENSE_LENGTH || underlying instanceof SparseArrayData) {
return underlying;
}
return new SparseArrayData(underlying, underlying.length());
return new SparseArrayData(underlying, underlying.length);
}
private boolean isEmpty() {
@ -93,7 +93,7 @@ final class DeletedRangeArrayFilter extends ArrayFilter {
@Override
public ArrayData ensure(final long safeIndex) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH && safeIndex >= length()) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH && safeIndex >= length) {
return new SparseArrayData(this, safeIndex + 1);
}
@ -110,8 +110,9 @@ final class DeletedRangeArrayFilter extends ArrayFilter {
@Override
public ArrayData shiftRight(final int by) {
super.shiftRight(by);
lo = Math.min(length(), lo + by);
hi = Math.min(length() - 1, hi + by);
final long len = length;
lo = Math.min(len, lo + by);
hi = Math.min(len - 1, hi + by);
return isEmpty() ? getUnderlying() : this;
}
@ -237,7 +238,7 @@ final class DeletedRangeArrayFilter extends ArrayFilter {
@Override
public Object pop() {
final int index = (int)(length() - 1);
final int index = (int)length - 1;
if (super.has(index)) {
final boolean isDeleted = isDeleted(index);
final Object value = super.pop();

View File

@ -105,13 +105,13 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
@Override
public ArrayData copy() {
return new IntArrayData(array.clone(), (int) length());
return new IntArrayData(array.clone(), (int)length);
}
@Override
public Object asArrayOfType(final Class<?> componentType) {
if (componentType == int.class) {
return array.length == length() ? array.clone() : Arrays.copyOf(array, (int) length());
return array.length == length ? array.clone() : Arrays.copyOf(array, (int)length);
}
return super.asArrayOfType(componentType);
}
@ -183,7 +183,7 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
@Override
public ArrayData shiftRight(final int by) {
final ArrayData newData = ensure(by + length() - 1);
final ArrayData newData = ensure(by + length - 1);
if (newData != this) {
newData.shiftRight(by);
return newData;
@ -229,7 +229,7 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
@Override
public ArrayData set(final int index, final int value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@ -238,7 +238,7 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
public ArrayData set(final int index, final long value, final boolean strict) {
if (JSType.isRepresentableAsInt(value)) {
array[index] = JSType.toInt32(value);
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@ -249,7 +249,7 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
public ArrayData set(final int index, final double value, final boolean strict) {
if (JSType.isRepresentableAsInt(value)) {
array[index] = (int)(long)value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@ -298,7 +298,7 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
@Override
public boolean has(final int index) {
return 0 <= index && index < length();
return 0 <= index && index < length;
}
@Override
@ -313,11 +313,11 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
@Override
public Object pop() {
if (length() == 0) {
if (length == 0) {
return ScriptRuntime.UNDEFINED;
}
final int newLength = (int) length() - 1;
final int newLength = (int)length - 1;
final int elem = array[newLength];
array[newLength] = 0;
setLength(newLength);
@ -327,7 +327,7 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
@Override
public ArrayData slice(final long from, final long to) {
final long start = from < 0 ? from + length() : from;
final long start = from < 0 ? from + length : from;
final long newLength = to - start;
return new IntArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
@ -335,18 +335,18 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
@Override
public final ArrayData push(final boolean strict, final int item) {
final long length = length();
final ArrayData newData = ensure(length);
final long len = length;
final ArrayData newData = ensure(len);
if (newData == this) {
array[(int)length] = item;
array[(int)len] = item;
return this;
}
return newData.set((int)length, item, strict);
return newData.set((int)len, item, strict);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long oldLength = length;
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();

View File

@ -62,12 +62,12 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
@Override
public ArrayData copy() {
return new LongArrayData(array.clone(), (int)length());
return new LongArrayData(array.clone(), (int)length);
}
@Override
public Object[] asObjectArray() {
return toObjectArray(array, (int)length());
return toObjectArray(array, (int)length);
}
private static Object[] toObjectArray(final long[] array, final int length) {
@ -84,7 +84,7 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
@Override
public Object asArrayOfType(final Class<?> componentType) {
if (componentType == long.class) {
return array.length == length() ? array.clone() : Arrays.copyOf(array, (int)length());
return array.length == length ? array.clone() : Arrays.copyOf(array, (int)length);
}
return super.asArrayOfType(componentType);
}
@ -105,11 +105,11 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
if (type == Integer.class || type == Long.class) {
return this;
}
final int length = (int) length();
final int len = (int)length;
if (type == Double.class) {
return new NumberArrayData(LongArrayData.toDoubleArray(array, length), length);
return new NumberArrayData(LongArrayData.toDoubleArray(array, len), len);
}
return new ObjectArrayData(LongArrayData.toObjectArray(array, length), length);
return new ObjectArrayData(LongArrayData.toObjectArray(array, len), len);
}
@Override
@ -119,7 +119,7 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
@Override
public ArrayData shiftRight(final int by) {
final ArrayData newData = ensure(by + length() - 1);
final ArrayData newData = ensure(by + length - 1);
if (newData != this) {
newData.shiftRight(by);
return newData;
@ -165,14 +165,14 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
@Override
public ArrayData set(final int index, final int value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@Override
public ArrayData set(final int index, final long value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@ -180,7 +180,7 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
public ArrayData set(final int index, final double value, final boolean strict) {
if (JSType.isRepresentableAsLong(value)) {
array[index] = (long)value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
return convert(Double.class).set(index, value, strict);
@ -256,7 +256,7 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
@Override
public boolean has(final int index) {
return 0 <= index && index < length();
return 0 <= index && index < length;
}
@Override
@ -271,11 +271,11 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
@Override
public Object pop() {
if (length() == 0) {
if (length == 0) {
return ScriptRuntime.UNDEFINED;
}
final int newLength = (int) (length() - 1);
final int newLength = (int)length - 1;
final long elem = array[newLength];
array[newLength] = 0;
setLength(newLength);
@ -285,25 +285,25 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
@Override
public ArrayData slice(final long from, final long to) {
final long start = from < 0 ? from + length() : from;
final long start = from < 0 ? from + length : from;
final long newLength = to - start;
return new LongArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
}
@Override
public final ArrayData push(final boolean strict, final long item) {
final long length = length();
final ArrayData newData = ensure(length);
final long len = length;
final ArrayData newData = ensure(len);
if (newData == this) {
array[(int)length] = item;
array[(int)len] = item;
return this;
}
return newData.set((int)length, item, strict);
return newData.set((int)len, item, strict);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long oldLength = length;
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();
@ -353,7 +353,6 @@ final class LongArrayData extends ContinuousArrayData implements IntOrLongElemen
final long elem = array[newLength];
array[newLength] = 0;
return elem;
//return array[(int)--length];
}
@Override

View File

@ -58,19 +58,19 @@ final class NoTypeArrayData extends ArrayData {
@Override
public ArrayData convert(final Class<?> type) {
final long length = length();
final long len = length;
final ArrayData arrayData;
if (type == Long.class) {
arrayData = new LongArrayData(new long[ArrayData.nextSize((int)length)], (int)length);
arrayData = new LongArrayData(new long[ArrayData.nextSize((int)len)], (int)len);
} else if (type == Double.class) {
arrayData = new NumberArrayData(new double[ArrayData.nextSize((int)length)], (int)length);
arrayData = new NumberArrayData(new double[ArrayData.nextSize((int)len)], (int)len);
} else if (type == Integer.class) {
arrayData = new IntArrayData(new int[ArrayData.nextSize((int)length)], (int)length);
arrayData = new IntArrayData(new int[ArrayData.nextSize((int)len)], (int)len);
} else {
assert !type.isPrimitive();
arrayData = new ObjectArrayData(new Object[ArrayData.nextSize((int)length)], (int)length);
arrayData = new ObjectArrayData(new Object[ArrayData.nextSize((int)len)], (int)len);
}
return length == 0 ? arrayData : new DeletedRangeArrayFilter(arrayData, 0, length - 1);
return length == 0 ? arrayData : new DeletedRangeArrayFilter(arrayData, 0, len - 1);
}
@Override
@ -90,11 +90,11 @@ final class NoTypeArrayData extends ArrayData {
}
// Don't trample the shared EMPTY_ARRAY.
if (length() == 0) {
return new NoTypeArrayData(Math.max(safeIndex + 1, length()));
if (length == 0) {
return new NoTypeArrayData(Math.max(safeIndex + 1, length));
}
setLength(Math.max(safeIndex + 1, length()));
setLength(Math.max(safeIndex + 1, length));
return this;
}

View File

@ -61,12 +61,12 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public ArrayData copy() {
return new NumberArrayData(array.clone(), (int) length());
return new NumberArrayData(array.clone(), (int)length);
}
@Override
public Object[] asObjectArray() {
return toObjectArray(array, (int) length());
return toObjectArray(array, (int)length);
}
private static Object[] toObjectArray(final double[] array, final int length) {
@ -82,7 +82,7 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public Object asArrayOfType(final Class<?> componentType) {
if(componentType == double.class) {
return array.length == length() ? array.clone() : Arrays.copyOf(array, (int) length());
return array.length == length ? array.clone() : Arrays.copyOf(array, (int)length);
}
return super.asArrayOfType(componentType);
}
@ -90,8 +90,8 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public ArrayData convert(final Class<?> type) {
if (type != Double.class && type != Integer.class && type != Long.class) {
final int length = (int) length();
return new ObjectArrayData(NumberArrayData.toObjectArray(array, length), length);
final int len = (int)length;
return new ObjectArrayData(NumberArrayData.toObjectArray(array, len), len);
}
return this;
}
@ -103,7 +103,7 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public ArrayData shiftRight(final int by) {
final ArrayData newData = ensure(by + length() - 1);
final ArrayData newData = ensure(by + length - 1);
if (newData != this) {
newData.shiftRight(by);
return newData;
@ -148,21 +148,21 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public ArrayData set(final int index, final int value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@Override
public ArrayData set(final int index, final long value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@Override
public ArrayData set(final int index, final double value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@ -231,7 +231,7 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public boolean has(final int index) {
return 0 <= index && index < length();
return 0 <= index && index < length;
}
@Override
@ -246,11 +246,11 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public Object pop() {
if (length() == 0) {
if (length == 0) {
return UNDEFINED;
}
final int newLength = (int) (length() - 1);
final int newLength = (int)length - 1;
final double elem = array[newLength];
array[newLength] = 0;
setLength(newLength);
@ -259,25 +259,25 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
@Override
public ArrayData slice(final long from, final long to) {
final long start = from < 0 ? from + length() : from;
final long start = from < 0 ? from + length : from;
final long newLength = to - start;
return new NumberArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
}
@Override
public final ArrayData push(final boolean strict, final double item) {
final long length = length();
final ArrayData newData = ensure(length);
final long len = length;
final ArrayData newData = ensure(len);
if (newData == this) {
array[(int)length] = item;
array[(int)len] = item;
return this;
}
return newData.set((int)length, item, strict);
return newData.set((int)len, item, strict);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long oldLength = length;
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();

View File

@ -67,14 +67,14 @@ final class ObjectArrayData extends ContinuousArrayData {
@Override
public Object[] asObjectArray() {
return array.length == length() ? array.clone() : asObjectArrayCopy();
return array.length == length ? array.clone() : asObjectArrayCopy();
}
private Object[] asObjectArrayCopy() {
final long l = length();
assert l <= Integer.MAX_VALUE;
final Object[] copy = new Object[(int)l];
System.arraycopy(array, 0, copy, 0, (int)l);
final long len = length;
assert len <= Integer.MAX_VALUE;
final Object[] copy = new Object[(int)len];
System.arraycopy(array, 0, copy, 0, (int)len);
return copy;
}
@ -90,7 +90,7 @@ final class ObjectArrayData extends ContinuousArrayData {
@Override
public ArrayData shiftRight(final int by) {
final ArrayData newData = ensure(by + length() - 1);
final ArrayData newData = ensure(by + length - 1);
if (newData != this) {
newData.shiftRight(by);
return newData;
@ -122,28 +122,28 @@ final class ObjectArrayData extends ContinuousArrayData {
@Override
public ArrayData set(final int index, final Object value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@Override
public ArrayData set(final int index, final int value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@Override
public ArrayData set(final int index, final long value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@Override
public ArrayData set(final int index, final double value, final boolean strict) {
array[index] = value;
setLength(Math.max(index + 1, length()));
setLength(Math.max(index + 1, length));
return this;
}
@ -220,7 +220,7 @@ final class ObjectArrayData extends ContinuousArrayData {
@Override
public boolean has(final int index) {
return 0 <= index && index < length();
return 0 <= index && index < length;
}
@Override
@ -273,11 +273,11 @@ final class ObjectArrayData extends ContinuousArrayData {
@Override
public Object pop() {
if (length() == 0) {
if (length == 0) {
return ScriptRuntime.UNDEFINED;
}
final int newLength = (int) (length() - 1);
final int newLength = (int)length - 1;
final Object elem = array[newLength];
setEmpty(newLength);
setLength(newLength);
@ -286,25 +286,25 @@ final class ObjectArrayData extends ContinuousArrayData {
@Override
public ArrayData slice(final long from, final long to) {
final long start = from < 0 ? from + length() : from;
final long start = from < 0 ? from + length : from;
final long newLength = to - start;
return new ObjectArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
}
@Override
public ArrayData push(final boolean strict, final Object item) {
final long length = length();
final ArrayData newData = ensure(length);
final long len = length;
final ArrayData newData = ensure(len);
if (newData == this) {
array[(int)length] = item;
array[(int)len] = item;
return this;
}
return newData.set((int)length, item, strict);
return newData.set((int)len, item, strict);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long oldLength = length;
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();

View File

@ -53,28 +53,28 @@ class SparseArrayData extends ArrayData {
SparseArrayData(final ArrayData underlying, final long length, final TreeMap<Long, Object> sparseMap) {
super(length);
assert underlying.length() <= length;
assert underlying.length <= length;
this.underlying = underlying;
this.maxDenseLength = Math.max(MAX_DENSE_LENGTH, underlying.length());
this.maxDenseLength = Math.max(MAX_DENSE_LENGTH, underlying.length);
this.sparseMap = sparseMap;
}
@Override
public ArrayData copy() {
return new SparseArrayData(underlying.copy(), length(), new TreeMap<>(sparseMap));
return new SparseArrayData(underlying.copy(), length, new TreeMap<>(sparseMap));
}
@Override
public Object[] asObjectArray() {
final int length = (int) Math.min(length(), Integer.MAX_VALUE);
final int underlyingLength = (int) Math.min(length, underlying.length());
final Object[] objArray = new Object[length];
final int len = (int)Math.min(length, Integer.MAX_VALUE);
final int underlyingLength = (int)Math.min(len, underlying.length);
final Object[] objArray = new Object[len];
for (int i = 0; i < underlyingLength; i++) {
objArray[i] = underlying.getObject(i);
}
Arrays.fill(objArray, underlyingLength, length, ScriptRuntime.UNDEFINED);
Arrays.fill(objArray, underlyingLength, len, ScriptRuntime.UNDEFINED);
for (final Map.Entry<Long, Object> entry : sparseMap.entrySet()) {
final long key = entry.getKey();
@ -104,14 +104,14 @@ class SparseArrayData extends ArrayData {
}
sparseMap = newSparseMap;
setLength(Math.max(length() - by, 0));
setLength(Math.max(length - by, 0));
}
@Override
public ArrayData shiftRight(final int by) {
final TreeMap<Long, Object> newSparseMap = new TreeMap<>();
if (underlying.length() + by > maxDenseLength) {
for (long i = maxDenseLength - by; i < underlying.length(); i++) {
if (underlying.length + by > maxDenseLength) {
for (long i = maxDenseLength - by; i < underlying.length; i++) {
if (underlying.has((int) i)) {
newSparseMap.put(Long.valueOf(i + by), underlying.getObject((int) i));
}
@ -127,23 +127,23 @@ class SparseArrayData extends ArrayData {
}
sparseMap = newSparseMap;
setLength(length() + by);
setLength(length + by);
return this;
}
@Override
public ArrayData ensure(final long safeIndex) {
if (safeIndex < maxDenseLength && underlying.length() <= safeIndex) {
if (safeIndex < maxDenseLength && underlying.length <= safeIndex) {
underlying = underlying.ensure(safeIndex);
}
setLength(Math.max(safeIndex + 1, length()));
setLength(Math.max(safeIndex + 1, length));
return this;
}
@Override
public ArrayData shrink(final long newLength) {
if (newLength < underlying.length()) {
if (newLength < underlying.length) {
underlying = underlying.shrink(newLength);
underlying.setLength(newLength);
sparseMap.clear();
@ -160,11 +160,11 @@ class SparseArrayData extends ArrayData {
if (index >= 0 && index < maxDenseLength) {
ensure(index);
underlying = underlying.set(index, value, strict);
setLength(Math.max(underlying.length(), length()));
setLength(Math.max(underlying.length, length));
} else {
final Long longIndex = indexToKey(index);
sparseMap.put(longIndex, value);
setLength(Math.max(longIndex + 1, length()));
setLength(Math.max(longIndex + 1, length));
}
return this;
@ -175,11 +175,11 @@ class SparseArrayData extends ArrayData {
if (index >= 0 && index < maxDenseLength) {
ensure(index);
underlying = underlying.set(index, value, strict);
setLength(Math.max(underlying.length(), length()));
setLength(Math.max(underlying.length, length));
} else {
final Long longIndex = indexToKey(index);
sparseMap.put(longIndex, value);
setLength(Math.max(longIndex + 1, length()));
setLength(Math.max(longIndex + 1, length));
}
return this;
}
@ -189,11 +189,11 @@ class SparseArrayData extends ArrayData {
if (index >= 0 && index < maxDenseLength) {
ensure(index);
underlying = underlying.set(index, value, strict);
setLength(Math.max(underlying.length(), length()));
setLength(Math.max(underlying.length, length));
} else {
final Long longIndex = indexToKey(index);
sparseMap.put(longIndex, value);
setLength(Math.max(longIndex + 1, length()));
setLength(Math.max(longIndex + 1, length));
}
return this;
}
@ -203,11 +203,11 @@ class SparseArrayData extends ArrayData {
if (index >= 0 && index < maxDenseLength) {
ensure(index);
underlying = underlying.set(index, value, strict);
setLength(Math.max(underlying.length(), length()));
setLength(Math.max(underlying.length, length));
} else {
final Long longIndex = indexToKey(index);
sparseMap.put(longIndex, value);
setLength(Math.max(longIndex + 1, length()));
setLength(Math.max(longIndex + 1, length));
}
return this;
}
@ -294,7 +294,7 @@ class SparseArrayData extends ArrayData {
@Override
public boolean has(final int index) {
if (index >= 0 && index < maxDenseLength) {
return index < underlying.length() && underlying.has(index);
return index < underlying.length && underlying.has(index);
}
return sparseMap.containsKey(indexToKey(index));
@ -303,7 +303,7 @@ class SparseArrayData extends ArrayData {
@Override
public ArrayData delete(final int index) {
if (index >= 0 && index < maxDenseLength) {
if (index < underlying.length()) {
if (index < underlying.length) {
underlying = underlying.delete(index);
}
} else {
@ -315,8 +315,8 @@ class SparseArrayData extends ArrayData {
@Override
public ArrayData delete(final long fromIndex, final long toIndex) {
if (fromIndex < maxDenseLength && fromIndex < underlying.length()) {
underlying = underlying.delete(fromIndex, Math.min(toIndex, underlying.length() - 1));
if (fromIndex < maxDenseLength && fromIndex < underlying.length) {
underlying = underlying.delete(fromIndex, Math.min(toIndex, underlying.length - 1));
}
if (toIndex >= maxDenseLength) {
sparseMap.subMap(fromIndex, true, toIndex, true).clear();
@ -336,30 +336,30 @@ class SparseArrayData extends ArrayData {
@Override
public Object pop() {
if (length() == 0) {
if (length == 0) {
return ScriptRuntime.UNDEFINED;
}
if (length() == underlying.length()) {
if (length == underlying.length) {
final Object result = underlying.pop();
setLength(underlying.length());
setLength(underlying.length);
return result;
}
setLength(length() - 1);
final Long key = Long.valueOf(length());
setLength(length - 1);
final Long key = Long.valueOf(length);
return sparseMap.containsKey(key) ? sparseMap.remove(key) : ScriptRuntime.UNDEFINED;
}
@Override
public ArrayData slice(final long from, final long to) {
assert to <= length();
final long start = from < 0 ? (from + length()) : from;
assert to <= length;
final long start = from < 0 ? (from + length) : from;
final long newLength = to - start;
if (start >= 0 && to <= maxDenseLength) {
if (newLength <= underlying.length()) {
if (newLength <= underlying.length) {
return underlying.slice(from, to);
}
return underlying.slice(from, to).ensure(newLength - 1).delete(underlying.length(), newLength);
return underlying.slice(from, to).ensure(newLength - 1).delete(underlying.length, newLength);
}
ArrayData sliced = EMPTY_ARRAY;
@ -369,13 +369,13 @@ class SparseArrayData extends ArrayData {
sliced = sliced.set((int)(i - start), getObject((int)i), false);
}
}
assert sliced.length() == newLength;
assert sliced.length == newLength;
return sliced;
}
@Override
public long nextIndex(final long index) {
if (index < underlying.length() - 1) {
if (index < underlying.length - 1) {
return underlying.nextIndex(index);
}
@ -383,6 +383,6 @@ class SparseArrayData extends ArrayData {
if (nextKey != null) {
return nextKey;
}
return length();
return length;
}
}

View File

@ -54,11 +54,11 @@ public abstract class TypedArrayData<T extends Buffer> extends ContinuousArrayDa
}
/**
* Length in elements. Accessed from {@code ArrayBufferView}
* Length in number of elements. Accessed from {@code ArrayBufferView}
* @return element length
*/
public final int getElementLength() {
return (int)length();
return (int)length;
}
/**
@ -119,7 +119,7 @@ public abstract class TypedArrayData<T extends Buffer> extends ContinuousArrayDa
@Override
public final boolean has(final int index) {
return 0 <= index && index < length();
return 0 <= index && index < length;
}
@Override

View File

@ -26,7 +26,6 @@
package jdk.nashorn.internal.runtime.arrays;
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import java.lang.reflect.Array;
import jdk.nashorn.internal.runtime.BitVector;
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
@ -41,7 +40,7 @@ final class UndefinedArrayFilter extends ArrayFilter {
UndefinedArrayFilter(final ArrayData underlying) {
super(underlying);
this.undefined = new BitVector(underlying.length());
this.undefined = new BitVector(underlying.length);
}
@Override
@ -81,25 +80,25 @@ final class UndefinedArrayFilter extends ArrayFilter {
@Override
public void shiftLeft(final int by) {
super.shiftLeft(by);
undefined.shiftLeft(by, length());
undefined.shiftLeft(by, length);
}
@Override
public ArrayData shiftRight(final int by) {
super.shiftRight(by);
undefined.shiftRight(by, length());
undefined.shiftRight(by, length);
return this;
}
@Override
public ArrayData ensure(final long safeIndex) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH && safeIndex >= length()) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH && safeIndex >= length) {
return new SparseArrayData(this, safeIndex + 1);
}
super.ensure(safeIndex);
undefined.resize(length());
undefined.resize(length);
return this;
}
@ -107,7 +106,7 @@ final class UndefinedArrayFilter extends ArrayFilter {
@Override
public ArrayData shrink(final long newLength) {
super.shrink(newLength);
undefined.resize(length());
undefined.resize(length);
return this;
}
@ -217,7 +216,7 @@ final class UndefinedArrayFilter extends ArrayFilter {
@Override
public Object pop() {
final long index = length() - 1;
final long index = length - 1;
if (super.has((int)index)) {
final boolean isUndefined = undefined.isSet(index);
@ -234,7 +233,7 @@ final class UndefinedArrayFilter extends ArrayFilter {
final ArrayData newArray = underlying.slice(from, to);
final UndefinedArrayFilter newFilter = new UndefinedArrayFilter(newArray);
newFilter.getUndefined().copy(undefined);
newFilter.getUndefined().shiftLeft(from, newFilter.length());
newFilter.getUndefined().shiftLeft(from, newFilter.length);
return newFilter;
}