[cvs] / jsr166 / src / main / java / util / Vector.java Repository:
ViewVC logotype

Diff of /jsr166/src/main/java/util/Vector.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.39, Fri Dec 2 06:38:56 2016 UTC revision 1.40, Mon Dec 5 00:08:01 2016 UTC
# Line 306  Line 306 
306          modCount++;          modCount++;
307          if (newSize > elementData.length)          if (newSize > elementData.length)
308              grow(newSize);              grow(newSize);
309          for (int i = newSize; i < elementCount; i++)          final Object[] es = elementData;
310              elementData[i] = null;          for (int to = elementCount, i = elementCount = newSize; i < to; i++)
311          elementCount = newSize;              es[i] = null;
312      }      }
313    
314      /**      /**
# Line 676  Line 676 
676       * method (which is part of the {@link List} interface).       * method (which is part of the {@link List} interface).
677       */       */
678      public synchronized void removeAllElements() {      public synchronized void removeAllElements() {
679          Arrays.fill(elementData, 0, elementCount, null);          final Object[] es = elementData;
680            for (int to = elementCount, i = elementCount = 0; i < to; i++)
681                es[i] = null;
682          modCount++;          modCount++;
         elementCount = 0;  
683      }      }
684    
685      /**      /**
# Line 1028  Line 1029 
1029              for (i = beg; i < end; i++)              for (i = beg; i < end; i++)
1030                  if (isClear(deathRow, i - beg))                  if (isClear(deathRow, i - beg))
1031                      es[w++] = es[i];                      es[w++] = es[i];
1032              Arrays.fill(es, elementCount = w, end, null);              for (i = elementCount = w; i < end; i++)
1033                    es[i] = null;
1034              // checkInvariants();              // checkInvariants();
1035              return true;              return true;
1036          } else {          } else {
# Line 1159  Line 1161 
1161       * (If {@code toIndex==fromIndex}, this operation has no effect.)       * (If {@code toIndex==fromIndex}, this operation has no effect.)
1162       */       */
1163      protected synchronized void removeRange(int fromIndex, int toIndex) {      protected synchronized void removeRange(int fromIndex, int toIndex) {
         final Object[] es = elementData;  
         final int oldSize = elementCount;  
         System.arraycopy(es, toIndex, es, fromIndex, oldSize - toIndex);  
   
1164          modCount++;          modCount++;
1165          Arrays.fill(es, elementCount -= (toIndex - fromIndex), oldSize, null);          shiftTailOverGap(elementData, fromIndex, toIndex);
1166          // checkInvariants();          // checkInvariants();
1167      }      }
1168    
1169        /** Erases the gap from lo to hi, by sliding down following elements. */
1170        private void shiftTailOverGap(Object[] es, int lo, int hi) {
1171            System.arraycopy(es, hi, es, lo, elementCount - hi);
1172            for (int to = elementCount, i = (elementCount -= hi - lo); i < to; i++)
1173                es[i] = null;
1174        }
1175    
1176      /**      /**
1177       * Saves the state of the {@code Vector} instance to a stream       * Saves the state of the {@code Vector} instance to a stream
1178       * (that is, serializes it).       * (that is, serializes it).

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8