ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/Vector.java
(Generate patch)

Comparing jsr166/src/main/java/util/Vector.java (file contents):
Revision 1.34 by jsr166, Sun Nov 13 19:58:47 2016 UTC vs.
Revision 1.35 by jsr166, Sun Nov 13 21:07:40 2016 UTC

# Line 585 | Line 585 | public class Vector<E>
585          modCount++;
586          elementCount--;
587          elementData[elementCount] = null; /* to let gc do its work */
588 +        // checkInvariants();
589      }
590  
591      /**
# Line 675 | Line 676 | public class Vector<E>
676       * method (which is part of the {@link List} interface).
677       */
678      public synchronized void removeAllElements() {
679 <        // Let gc do its work
679 <        for (int i = 0; i < elementCount; i++)
680 <            elementData[i] = null;
681 <
679 >        Arrays.fill(elementData, 0, elementCount, null);
680          modCount++;
681          elementCount = 0;
682      }
# Line 810 | Line 808 | public class Vector<E>
808              elementData = grow();
809          elementData[s] = e;
810          elementCount = s + 1;
811 +        // checkInvariants();
812      }
813  
814      /**
# Line 878 | Line 877 | public class Vector<E>
877                               numMoved);
878          elementData[--elementCount] = null; // Let gc do its work
879  
880 +        // checkInvariants();
881          return oldValue;
882      }
883  
# Line 933 | Line 933 | public class Vector<E>
933                  elementData = grow(s + numNew);
934              System.arraycopy(a, 0, elementData, s, numNew);
935              elementCount = s + numNew;
936 +            // checkInvariants();
937              return true;
938          }
939      }
# Line 1030 | Line 1031 | public class Vector<E>
1031          }
1032          if (modCount != expectedModCount)
1033              throw new ConcurrentModificationException();
1034 +        // checkInvariants();
1035          return modified;
1036      }
1037  
# Line 1071 | Line 1073 | public class Vector<E>
1073                               numMoved);
1074          System.arraycopy(a, 0, elementData, index, numNew);
1075          elementCount = s + numNew;
1076 +        // checkInvariants();
1077          return true;
1078      }
1079  
# Line 1152 | Line 1155 | public class Vector<E>
1155       * (If {@code toIndex==fromIndex}, this operation has no effect.)
1156       */
1157      protected synchronized void removeRange(int fromIndex, int toIndex) {
1158 <        int numMoved = elementCount - toIndex;
1159 <        System.arraycopy(elementData, toIndex, elementData, fromIndex,
1160 <                         numMoved);
1161 <
1162 <        // Let gc do its work
1163 <        modCount++;
1164 <        int newElementCount = elementCount - (toIndex-fromIndex);
1162 <        while (elementCount != newElementCount)
1163 <            elementData[--elementCount] = null;
1158 >        final Object[] es = elementData;
1159 >        final int oldSize = elementCount;
1160 >        System.arraycopy(es, toIndex, es, fromIndex, oldSize - toIndex);
1161 >
1162 >        modCount++;
1163 >        Arrays.fill(es, elementCount -= (toIndex - fromIndex), oldSize, null);
1164 >        // checkInvariants();
1165      }
1166  
1167      /**
# Line 1350 | Line 1351 | public class Vector<E>
1351              action.accept(elementAt(es, i));
1352          if (modCount != expectedModCount)
1353              throw new ConcurrentModificationException();
1354 +        // checkInvariants();
1355      }
1356  
1357      @Override
# Line 1363 | Line 1365 | public class Vector<E>
1365          if (modCount != expectedModCount)
1366              throw new ConcurrentModificationException();
1367          modCount++;
1368 +        // checkInvariants();
1369      }
1370  
1371      @SuppressWarnings("unchecked")
# Line 1370 | Line 1373 | public class Vector<E>
1373      public synchronized void sort(Comparator<? super E> c) {
1374          final int expectedModCount = modCount;
1375          Arrays.sort((E[]) elementData, 0, elementCount, c);
1376 <        if (modCount != expectedModCount) {
1376 >        if (modCount != expectedModCount)
1377              throw new ConcurrentModificationException();
1375        }
1378          modCount++;
1379 +        // checkInvariants();
1380      }
1381  
1382      /**
# Line 1480 | Line 1483 | public class Vector<E>
1483              return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
1484          }
1485      }
1486 +
1487 +    void checkInvariants() {
1488 +        // assert elementCount >= 0;
1489 +        // assert elementCount == elementData.length || elementData[elementCount] == null;
1490 +    }
1491   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines