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.33 by jsr166, Sun Nov 13 02:10:09 2016 UTC vs.
Revision 1.34 by jsr166, Sun Nov 13 19:58:47 2016 UTC

# Line 693 | Line 693 | public class Vector<E>
693      public synchronized Object clone() {
694          try {
695              @SuppressWarnings("unchecked")
696 <                Vector<E> v = (Vector<E>) super.clone();
696 >            Vector<E> v = (Vector<E>) super.clone();
697              v.elementData = Arrays.copyOf(elementData, elementCount);
698              v.modCount = 0;
699              return v;
# Line 1269 | Line 1269 | public class Vector<E>
1269                  if (i >= size) {
1270                      return;
1271                  }
1272 <        @SuppressWarnings("unchecked")
1273 <                final E[] elementData = (E[]) Vector.this.elementData;
1274 <                if (i >= elementData.length) {
1272 >                final Object[] es = elementData;
1273 >                if (i >= es.length)
1274                      throw new ConcurrentModificationException();
1275 <                }
1276 <                while (i != size && modCount == expectedModCount) {
1278 <                    action.accept(elementData[i++]);
1279 <                }
1275 >                while (i < size && modCount == expectedModCount)
1276 >                    action.accept(elementAt(es, i++));
1277                  // update once at end of iteration to reduce heap write traffic
1278                  cursor = i;
1279                  lastRet = i - 1;
# Line 1347 | Line 1344 | public class Vector<E>
1344      public synchronized void forEach(Consumer<? super E> action) {
1345          Objects.requireNonNull(action);
1346          final int expectedModCount = modCount;
1347 <        @SuppressWarnings("unchecked")
1348 <        final E[] elementData = (E[]) this.elementData;
1349 <        final int elementCount = this.elementCount;
1350 <        for (int i=0; modCount == expectedModCount && i < elementCount; i++) {
1351 <            action.accept(elementData[i]);
1355 <        }
1356 <        if (modCount != expectedModCount) {
1347 >        final Object[] es = elementData;
1348 >        final int size = elementCount;
1349 >        for (int i = 0; modCount == expectedModCount && i < size; i++)
1350 >            action.accept(elementAt(es, i));
1351 >        if (modCount != expectedModCount)
1352              throw new ConcurrentModificationException();
1358        }
1353      }
1354  
1355      @Override
1362    @SuppressWarnings("unchecked")
1356      public synchronized void replaceAll(UnaryOperator<E> operator) {
1357          Objects.requireNonNull(operator);
1358          final int expectedModCount = modCount;
1359 +        final Object[] es = elementData;
1360          final int size = elementCount;
1361 <        for (int i=0; modCount == expectedModCount && i < size; i++) {
1362 <            elementData[i] = operator.apply((E) elementData[i]);
1363 <        }
1370 <        if (modCount != expectedModCount) {
1361 >        for (int i = 0; modCount == expectedModCount && i < size; i++)
1362 >            es[i] = operator.apply(elementAt(es, i));
1363 >        if (modCount != expectedModCount)
1364              throw new ConcurrentModificationException();
1372        }
1365          modCount++;
1366      }
1367  
# Line 1410 | Line 1402 | public class Vector<E>
1402          private int fence; // -1 until used; then one past last index
1403          private int expectedModCount; // initialized when fence set
1404  
1405 <        /** Create new spliterator covering the given  range */
1405 >        /** Create new spliterator covering the given range */
1406          VectorSpliterator(Vector<E> list, Object[] array, int origin, int fence,
1407                            int expectedModCount) {
1408              this.list = list;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines