1537 |
|
return removeIf(filter, 0, size); |
1538 |
|
} |
1539 |
|
|
1540 |
< |
boolean removeIf(Predicate<? super E> filter, |
1541 |
< |
final int from, final int end) { |
1540 |
> |
/** |
1541 |
> |
* Removes all elements satisfying the given predicate, from index |
1542 |
> |
* i (inclusive) to index end (exclusive). |
1543 |
> |
*/ |
1544 |
> |
boolean removeIf(Predicate<? super E> filter, int i, final int end) { |
1545 |
|
Objects.requireNonNull(filter); |
1546 |
|
int expectedModCount = modCount; |
1547 |
|
final Object[] es = elementData; |
1545 |
– |
final boolean modified; |
1546 |
– |
int i; |
1548 |
|
// Optimize for initial run of survivors |
1549 |
< |
for (i = from; i < end && !filter.test(elementAt(es, i)); i++) |
1549 |
> |
for (; i < end && !filter.test(elementAt(es, i)); i++) |
1550 |
|
; |
1551 |
|
// Tolerate predicates that reentrantly access the collection for |
1552 |
|
// read (but writers still get CME), so traverse once to find |
1553 |
|
// elements to delete, a second pass to physically expunge. |
1554 |
< |
if (modified = (i < end)) { |
1554 |
< |
expectedModCount++; |
1555 |
< |
modCount++; |
1554 |
> |
if (i < end) { |
1555 |
|
final int beg = i; |
1556 |
|
final long[] deathRow = nBits(end - beg); |
1557 |
|
deathRow[0] = 1L; // set bit 0 |
1560 |
|
setBit(deathRow, i - beg); |
1561 |
|
if (modCount != expectedModCount) |
1562 |
|
throw new ConcurrentModificationException(); |
1563 |
+ |
expectedModCount++; |
1564 |
+ |
modCount++; |
1565 |
|
int w = beg; |
1566 |
|
for (i = beg; i < end; i++) |
1567 |
|
if (isClear(deathRow, i - beg)) |
1569 |
|
final int oldSize = size; |
1570 |
|
System.arraycopy(es, end, es, w, oldSize - end); |
1571 |
|
Arrays.fill(es, size -= (end - w), oldSize, null); |
1572 |
+ |
// checkInvariants(); |
1573 |
+ |
return true; |
1574 |
+ |
} else { |
1575 |
+ |
if (modCount != expectedModCount) |
1576 |
+ |
throw new ConcurrentModificationException(); |
1577 |
+ |
// checkInvariants(); |
1578 |
+ |
return false; |
1579 |
|
} |
1572 |
– |
if (modCount != expectedModCount) |
1573 |
– |
throw new ConcurrentModificationException(); |
1574 |
– |
// checkInvariants(); |
1575 |
– |
return modified; |
1580 |
|
} |
1581 |
|
|
1582 |
|
@Override |