mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8202685: Optimize ArrayList subList replaceAll
Reviewed-by: martin, psandoz, igerasim, redestad, dholmes, smarks, jrose, plevart
This commit is contained in:
parent
c9e23b5e71
commit
e4046542ba
2 changed files with 58 additions and 12 deletions
|
@ -1221,6 +1221,10 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
return true;
|
||||
}
|
||||
|
||||
public void replaceAll(UnaryOperator<E> operator) {
|
||||
root.replaceAllRange(operator, offset, offset + size);
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
return batchRemove(c, false);
|
||||
}
|
||||
|
@ -1724,15 +1728,18 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
|
||||
@Override
|
||||
public void replaceAll(UnaryOperator<E> operator) {
|
||||
replaceAllRange(operator, 0, size);
|
||||
modCount++;
|
||||
}
|
||||
|
||||
private void replaceAllRange(UnaryOperator<E> operator, int i, int end) {
|
||||
Objects.requireNonNull(operator);
|
||||
final int expectedModCount = modCount;
|
||||
final Object[] es = elementData;
|
||||
final int size = this.size;
|
||||
for (int i = 0; modCount == expectedModCount && i < size; i++)
|
||||
for (; modCount == expectedModCount && i < end; i++)
|
||||
es[i] = operator.apply(elementAt(es, i));
|
||||
if (modCount != expectedModCount)
|
||||
throw new ConcurrentModificationException();
|
||||
modCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue