< prev index next >

src/java.base/share/classes/java/util/ArrayList.java

Print this page
8203662: remove increment of modCount from ArrayList and Vector replaceAll()
Reviewed-by: martin, igerasim, redestad, dholmes, smarks, jrose, plevart


1712                     setBit(deathRow, i - beg);
1713             if (modCount != expectedModCount)
1714                 throw new ConcurrentModificationException();
1715             modCount++;
1716             int w = beg;
1717             for (i = beg; i < end; i++)
1718                 if (isClear(deathRow, i - beg))
1719                     es[w++] = es[i];
1720             shiftTailOverGap(es, w, end);
1721             return true;
1722         } else {
1723             if (modCount != expectedModCount)
1724                 throw new ConcurrentModificationException();
1725             return false;
1726         }
1727     }
1728 
1729     @Override
1730     public void replaceAll(UnaryOperator<E> operator) {
1731         replaceAllRange(operator, 0, size);
1732         modCount++;
1733     }
1734 
1735     private void replaceAllRange(UnaryOperator<E> operator, int i, int end) {
1736         Objects.requireNonNull(operator);
1737         final int expectedModCount = modCount;
1738         final Object[] es = elementData;
1739         for (; modCount == expectedModCount && i < end; i++)
1740             es[i] = operator.apply(elementAt(es, i));
1741         if (modCount != expectedModCount)
1742             throw new ConcurrentModificationException();
1743     }
1744 
1745     @Override
1746     @SuppressWarnings("unchecked")
1747     public void sort(Comparator<? super E> c) {
1748         final int expectedModCount = modCount;
1749         Arrays.sort((E[]) elementData, 0, size, c);
1750         if (modCount != expectedModCount)
1751             throw new ConcurrentModificationException();
1752         modCount++;


1712                     setBit(deathRow, i - beg);
1713             if (modCount != expectedModCount)
1714                 throw new ConcurrentModificationException();
1715             modCount++;
1716             int w = beg;
1717             for (i = beg; i < end; i++)
1718                 if (isClear(deathRow, i - beg))
1719                     es[w++] = es[i];
1720             shiftTailOverGap(es, w, end);
1721             return true;
1722         } else {
1723             if (modCount != expectedModCount)
1724                 throw new ConcurrentModificationException();
1725             return false;
1726         }
1727     }
1728 
1729     @Override
1730     public void replaceAll(UnaryOperator<E> operator) {
1731         replaceAllRange(operator, 0, size);

1732     }
1733 
1734     private void replaceAllRange(UnaryOperator<E> operator, int i, int end) {
1735         Objects.requireNonNull(operator);
1736         final int expectedModCount = modCount;
1737         final Object[] es = elementData;
1738         for (; modCount == expectedModCount && i < end; i++)
1739             es[i] = operator.apply(elementAt(es, i));
1740         if (modCount != expectedModCount)
1741             throw new ConcurrentModificationException();
1742     }
1743 
1744     @Override
1745     @SuppressWarnings("unchecked")
1746     public void sort(Comparator<? super E> c) {
1747         final int expectedModCount = modCount;
1748         Arrays.sort((E[]) elementData, 0, size, c);
1749         if (modCount != expectedModCount)
1750             throw new ConcurrentModificationException();
1751         modCount++;
< prev index next >