585 |
|
modCount++; |
586 |
|
elementCount--; |
587 |
|
elementData[elementCount] = null; /* to let gc do its work */ |
588 |
+ |
// checkInvariants(); |
589 |
|
} |
590 |
|
|
591 |
|
/** |
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 |
|
} |
808 |
|
elementData = grow(); |
809 |
|
elementData[s] = e; |
810 |
|
elementCount = s + 1; |
811 |
+ |
// checkInvariants(); |
812 |
|
} |
813 |
|
|
814 |
|
/** |
877 |
|
numMoved); |
878 |
|
elementData[--elementCount] = null; // Let gc do its work |
879 |
|
|
880 |
+ |
// checkInvariants(); |
881 |
|
return oldValue; |
882 |
|
} |
883 |
|
|
933 |
|
elementData = grow(s + numNew); |
934 |
|
System.arraycopy(a, 0, elementData, s, numNew); |
935 |
|
elementCount = s + numNew; |
936 |
+ |
// checkInvariants(); |
937 |
|
return true; |
938 |
|
} |
939 |
|
} |
1006 |
|
int expectedModCount = modCount; |
1007 |
|
final Object[] es = elementData; |
1008 |
|
final int end = elementCount; |
1008 |
– |
final boolean modified; |
1009 |
|
int i; |
1010 |
|
// Optimize for initial run of survivors |
1011 |
|
for (i = 0; i < end && !filter.test(elementAt(es, i)); i++) |
1013 |
|
// Tolerate predicates that reentrantly access the collection for |
1014 |
|
// read (but writers still get CME), so traverse once to find |
1015 |
|
// elements to delete, a second pass to physically expunge. |
1016 |
< |
if (modified = (i < end)) { |
1017 |
< |
expectedModCount++; |
1018 |
< |
modCount++; |
1016 |
> |
if (i < end) { |
1017 |
|
final int beg = i; |
1018 |
|
final long[] deathRow = nBits(end - beg); |
1019 |
|
deathRow[0] = 1L; // set bit 0 |
1020 |
|
for (i = beg + 1; i < end; i++) |
1021 |
|
if (filter.test(elementAt(es, i))) |
1022 |
|
setBit(deathRow, i - beg); |
1023 |
+ |
if (modCount != expectedModCount) |
1024 |
+ |
throw new ConcurrentModificationException(); |
1025 |
+ |
expectedModCount++; |
1026 |
+ |
modCount++; |
1027 |
|
int w = beg; |
1028 |
|
for (i = beg; i < end; i++) |
1029 |
|
if (isClear(deathRow, i - beg)) |
1030 |
|
es[w++] = es[i]; |
1031 |
|
Arrays.fill(es, elementCount = w, end, null); |
1032 |
+ |
// checkInvariants(); |
1033 |
+ |
return true; |
1034 |
+ |
} else { |
1035 |
+ |
if (modCount != expectedModCount) |
1036 |
+ |
throw new ConcurrentModificationException(); |
1037 |
+ |
// checkInvariants(); |
1038 |
+ |
return false; |
1039 |
|
} |
1031 |
– |
if (modCount != expectedModCount) |
1032 |
– |
throw new ConcurrentModificationException(); |
1033 |
– |
return modified; |
1040 |
|
} |
1041 |
|
|
1042 |
|
/** |
1077 |
|
numMoved); |
1078 |
|
System.arraycopy(a, 0, elementData, index, numNew); |
1079 |
|
elementCount = s + numNew; |
1080 |
+ |
// checkInvariants(); |
1081 |
|
return true; |
1082 |
|
} |
1083 |
|
|
1159 |
|
* (If {@code toIndex==fromIndex}, this operation has no effect.) |
1160 |
|
*/ |
1161 |
|
protected synchronized void removeRange(int fromIndex, int toIndex) { |
1162 |
< |
int numMoved = elementCount - toIndex; |
1163 |
< |
System.arraycopy(elementData, toIndex, elementData, fromIndex, |
1164 |
< |
numMoved); |
1165 |
< |
|
1166 |
< |
// Let gc do its work |
1167 |
< |
modCount++; |
1168 |
< |
int newElementCount = elementCount - (toIndex-fromIndex); |
1162 |
< |
while (elementCount != newElementCount) |
1163 |
< |
elementData[--elementCount] = null; |
1162 |
> |
final Object[] es = elementData; |
1163 |
> |
final int oldSize = elementCount; |
1164 |
> |
System.arraycopy(es, toIndex, es, fromIndex, oldSize - toIndex); |
1165 |
> |
|
1166 |
> |
modCount++; |
1167 |
> |
Arrays.fill(es, elementCount -= (toIndex - fromIndex), oldSize, null); |
1168 |
> |
// checkInvariants(); |
1169 |
|
} |
1170 |
|
|
1171 |
|
/** |
1355 |
|
action.accept(elementAt(es, i)); |
1356 |
|
if (modCount != expectedModCount) |
1357 |
|
throw new ConcurrentModificationException(); |
1358 |
+ |
// checkInvariants(); |
1359 |
|
} |
1360 |
|
|
1361 |
|
@Override |
1369 |
|
if (modCount != expectedModCount) |
1370 |
|
throw new ConcurrentModificationException(); |
1371 |
|
modCount++; |
1372 |
+ |
// checkInvariants(); |
1373 |
|
} |
1374 |
|
|
1375 |
|
@SuppressWarnings("unchecked") |
1377 |
|
public synchronized void sort(Comparator<? super E> c) { |
1378 |
|
final int expectedModCount = modCount; |
1379 |
|
Arrays.sort((E[]) elementData, 0, elementCount, c); |
1380 |
< |
if (modCount != expectedModCount) { |
1380 |
> |
if (modCount != expectedModCount) |
1381 |
|
throw new ConcurrentModificationException(); |
1375 |
– |
} |
1382 |
|
modCount++; |
1383 |
+ |
// checkInvariants(); |
1384 |
|
} |
1385 |
|
|
1386 |
|
/** |
1487 |
|
return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED; |
1488 |
|
} |
1489 |
|
} |
1490 |
+ |
|
1491 |
+ |
void checkInvariants() { |
1492 |
+ |
// assert elementCount >= 0; |
1493 |
+ |
// assert elementCount == elementData.length || elementData[elementCount] == null; |
1494 |
+ |
} |
1495 |
|
} |