< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java

Print this page




 178 
 179         return this;
 180     }
 181 
 182     @Override
 183     public ArrayData set(final int index, final int value, final boolean strict) {
 184         if (index >= 0 && index < maxDenseLength) {
 185             final long oldLength = underlying.length();
 186             ensure(index);
 187             underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
 188             setLength(Math.max(underlying.length(), length()));
 189         } else {
 190             final Long longIndex = indexToKey(index);
 191             sparseMap.put(longIndex, value);
 192             setLength(Math.max(longIndex + 1, length()));
 193         }
 194         return this;
 195     }
 196 
 197     @Override
 198     public ArrayData set(final int index, final long value, final boolean strict) {
 199         if (index >= 0 && index < maxDenseLength) {
 200             final long oldLength = underlying.length();
 201             ensure(index);
 202             underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
 203             setLength(Math.max(underlying.length(), length()));
 204         } else {
 205             final Long longIndex = indexToKey(index);
 206             sparseMap.put(longIndex, value);
 207             setLength(Math.max(longIndex + 1, length()));
 208         }
 209         return this;
 210     }
 211 
 212     @Override
 213     public ArrayData set(final int index, final double value, final boolean strict) {
 214         if (index >= 0 && index < maxDenseLength) {
 215             final long oldLength = underlying.length();
 216             ensure(index);
 217             underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
 218             setLength(Math.max(underlying.length(), length()));
 219         } else {
 220             final Long longIndex = indexToKey(index);
 221             sparseMap.put(longIndex, value);
 222             setLength(Math.max(longIndex + 1, length()));
 223         }
 224         return this;
 225     }
 226 
 227     @Override
 228     public ArrayData setEmpty(final int index) {
 229         underlying.setEmpty(index);
 230         return this;
 231     }
 232 


 238 
 239     @Override
 240     public Type getOptimisticType() {
 241         return underlying.getOptimisticType();
 242     }
 243 
 244     @Override
 245     public int getInt(final int index) {
 246         if (index >= 0 && index < maxDenseLength) {
 247             return underlying.getInt(index);
 248         }
 249         return JSType.toInt32(sparseMap.get(indexToKey(index)));
 250     }
 251 
 252     @Override
 253     public int getIntOptimistic(final int index, final int programPoint) {
 254         if (index >= 0 && index < maxDenseLength) {
 255             return underlying.getIntOptimistic(index, programPoint);
 256         }
 257         return JSType.toInt32Optimistic(sparseMap.get(indexToKey(index)), programPoint);
 258     }
 259 
 260     @Override
 261     public long getLong(final int index) {
 262         if (index >= 0 && index < maxDenseLength) {
 263             return underlying.getLong(index);
 264         }
 265         return JSType.toLong(sparseMap.get(indexToKey(index)));
 266     }
 267 
 268     @Override
 269     public long getLongOptimistic(final int index, final int programPoint) {
 270         if (index >= 0 && index < maxDenseLength) {
 271             return underlying.getLongOptimistic(index, programPoint);
 272         }
 273         return JSType.toLongOptimistic(sparseMap.get(indexToKey(index)), programPoint);
 274     }
 275 
 276     @Override
 277     public double getDouble(final int index) {
 278         if (index >= 0 && index < maxDenseLength) {
 279             return underlying.getDouble(index);
 280         }
 281         return JSType.toNumber(sparseMap.get(indexToKey(index)));
 282     }
 283 
 284     @Override
 285     public double getDoubleOptimistic(final int index, final int programPoint) {
 286         if (index >= 0 && index < maxDenseLength) {
 287             return underlying.getDouble(index);
 288         }
 289         return JSType.toNumberOptimistic(sparseMap.get(indexToKey(index)), programPoint);
 290     }
 291 
 292     @Override
 293     public Object getObject(final int index) {




 178 
 179         return this;
 180     }
 181 
 182     @Override
 183     public ArrayData set(final int index, final int value, final boolean strict) {
 184         if (index >= 0 && index < maxDenseLength) {
 185             final long oldLength = underlying.length();
 186             ensure(index);
 187             underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
 188             setLength(Math.max(underlying.length(), length()));
 189         } else {
 190             final Long longIndex = indexToKey(index);
 191             sparseMap.put(longIndex, value);
 192             setLength(Math.max(longIndex + 1, length()));
 193         }
 194         return this;
 195     }
 196 
 197     @Override















 198     public ArrayData set(final int index, final double value, final boolean strict) {
 199         if (index >= 0 && index < maxDenseLength) {
 200             final long oldLength = underlying.length();
 201             ensure(index);
 202             underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
 203             setLength(Math.max(underlying.length(), length()));
 204         } else {
 205             final Long longIndex = indexToKey(index);
 206             sparseMap.put(longIndex, value);
 207             setLength(Math.max(longIndex + 1, length()));
 208         }
 209         return this;
 210     }
 211 
 212     @Override
 213     public ArrayData setEmpty(final int index) {
 214         underlying.setEmpty(index);
 215         return this;
 216     }
 217 


 223 
 224     @Override
 225     public Type getOptimisticType() {
 226         return underlying.getOptimisticType();
 227     }
 228 
 229     @Override
 230     public int getInt(final int index) {
 231         if (index >= 0 && index < maxDenseLength) {
 232             return underlying.getInt(index);
 233         }
 234         return JSType.toInt32(sparseMap.get(indexToKey(index)));
 235     }
 236 
 237     @Override
 238     public int getIntOptimistic(final int index, final int programPoint) {
 239         if (index >= 0 && index < maxDenseLength) {
 240             return underlying.getIntOptimistic(index, programPoint);
 241         }
 242         return JSType.toInt32Optimistic(sparseMap.get(indexToKey(index)), programPoint);
















 243     }
 244 
 245     @Override
 246     public double getDouble(final int index) {
 247         if (index >= 0 && index < maxDenseLength) {
 248             return underlying.getDouble(index);
 249         }
 250         return JSType.toNumber(sparseMap.get(indexToKey(index)));
 251     }
 252 
 253     @Override
 254     public double getDoubleOptimistic(final int index, final int programPoint) {
 255         if (index >= 0 && index < maxDenseLength) {
 256             return underlying.getDouble(index);
 257         }
 258         return JSType.toNumberOptimistic(sparseMap.get(indexToKey(index)), programPoint);
 259     }
 260 
 261     @Override
 262     public Object getObject(final int index) {


< prev index next >