< prev index next >

src/jdk/nashorn/internal/runtime/arrays/ArrayData.java

Print this page

        

@@ -105,18 +105,17 @@
             return ScriptRuntime.EMPTY_ARRAY;
         }
 
         @Override
         public ArrayData ensure(final long safeIndex) {
-            if (safeIndex > 0L) {
+            assert safeIndex >= 0L;
                 if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH) {
                     return new SparseArrayData(this, safeIndex + 1);
                 }
                 //known to fit in int
                 return toRealArrayData((int)safeIndex);
-           }
-           return this;
+
         }
 
         @Override
         public ArrayData convert(final Class<?> type) {
             return toRealArrayData().convert(type);

@@ -131,12 +130,12 @@
         public ArrayData delete(final long fromIndex, final long toIndex) {
             return new DeletedRangeArrayFilter(this, fromIndex, toIndex);
         }
 
         @Override
-        public void shiftLeft(final int by) {
-            //nop, always empty or we wouldn't be of this class
+        public ArrayData shiftLeft(final int by) {
+            return this; //nop, always empty or we wouldn't be of this class
         }
 
         @Override
         public ArrayData shiftRight(final int by) {
             return this; //always empty or we wouldn't be of this class

@@ -449,17 +448,17 @@
     }
 
     /**
      * Shift the array data left
      *
-     * TODO: explore start at an index and not at zero, to make these operations
-     * even faster. Offset everything from the index. Costs memory but is probably
-     * worth it
+     * TODO: This is used for Array.prototype.shift() which only shifts by 1,
+     * so we might consider dropping the offset parameter.
      *
      * @param by offset to shift
+     * @return New arraydata (or same)
      */
-    public abstract void shiftLeft(final int by);
+    public abstract ArrayData shiftLeft(final int by);
 
     /**
      * Shift the array right
      *
      * @param by offset to shift
< prev index next >