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

Print this page

        

@@ -59,13 +59,13 @@
     public static final ArrayData EMPTY_ARRAY = new UntouchedArrayData();
 
     /**
      * Length of the array data. Not necessarily length of the wrapped array.
      * This is private to ensure that no one in a subclass is able to touch the length
-     * without going through {@link setLength}. This is used to implement
+     * without going through {@link #setLength}. This is used to implement
      * {@link LengthNotWritableFilter}s, ensuring that there are no ways past
-     * a {@link setLength} function replaced by a nop
+     * a {@link #setLength} function replaced by a nop
      */
     private long length;
 
     /**
      * Method handle to throw an {@link UnwarrantedOptimismException} when getting an element

@@ -77,15 +77,11 @@
      * Immutable empty array to get ScriptObjects started.
      * Use the same array and convert it to mutable as soon as it is modified
      */
     private static class UntouchedArrayData extends ContinuousArrayData {
         private UntouchedArrayData() {
-            this(0);
-        }
-
-        private UntouchedArrayData(final int length) {
-            super(length);
+            super(0);
         }
 
         private ArrayData toRealArrayData() {
             return toRealArrayData(0);
         }

@@ -98,11 +94,12 @@
             return new DeletedRangeArrayFilter(newData, 0, index);
         }
 
         @Override
         public ContinuousArrayData copy() {
-            return new UntouchedArrayData((int)length());
+            assert length() == 0;
+            return this;
         }
 
         @Override
         public Object asArrayOfType(final Class<?> componentType) {
             return Array.newInstance(componentType, 0);

@@ -244,11 +241,11 @@
 
         @Override
         public Class<?> getBoxedElementType() {
             return Integer.class;
         }
-    };
+    }
 
     /**
      * Constructor
      * @param length Virtual length of the array.
      */