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.36 by jsr166, Mon Nov 14 22:46:22 2016 UTC vs.
Revision 1.38 by jsr166, Thu Dec 1 00:35:21 2016 UTC

# Line 1398 | Line 1398 | public class Vector<E>
1398       */
1399      @Override
1400      public Spliterator<E> spliterator() {
1401 <        return new VectorSpliterator<>(this, null, 0, -1, 0);
1401 >        return new VectorSpliterator(null, 0, -1, 0);
1402      }
1403  
1404      /** Similar to ArrayList Spliterator */
1405 <    static final class VectorSpliterator<E> implements Spliterator<E> {
1406 <        private final Vector<E> list;
1405 >    final class VectorSpliterator implements Spliterator<E> {
1406          private Object[] array;
1407          private int index; // current index, modified on advance/split
1408          private int fence; // -1 until used; then one past last index
1409          private int expectedModCount; // initialized when fence set
1410  
1411          /** Create new spliterator covering the given range */
1412 <        VectorSpliterator(Vector<E> list, Object[] array, int origin, int fence,
1412 >        VectorSpliterator(Object[] array, int origin, int fence,
1413                            int expectedModCount) {
1415            this.list = list;
1414              this.array = array;
1415              this.index = origin;
1416              this.fence = fence;
# Line 1422 | Line 1420 | public class Vector<E>
1420          private int getFence() { // initialize on first use
1421              int hi;
1422              if ((hi = fence) < 0) {
1423 <                synchronized (list) {
1424 <                    array = list.elementData;
1425 <                    expectedModCount = list.modCount;
1426 <                    hi = fence = list.elementCount;
1423 >                synchronized (Vector.this) {
1424 >                    array = elementData;
1425 >                    expectedModCount = modCount;
1426 >                    hi = fence = elementCount;
1427                  }
1428              }
1429              return hi;
# Line 1434 | Line 1432 | public class Vector<E>
1432          public Spliterator<E> trySplit() {
1433              int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
1434              return (lo >= mid) ? null :
1435 <                new VectorSpliterator<>(list, array, lo, index = mid,
1438 <                                        expectedModCount);
1435 >                new VectorSpliterator(array, lo, index = mid, expectedModCount);
1436          }
1437  
1438          @SuppressWarnings("unchecked")
# Line 1446 | Line 1443 | public class Vector<E>
1443              if (getFence() > (i = index)) {
1444                  index = i + 1;
1445                  action.accept((E)array[i]);
1446 <                if (list.modCount != expectedModCount)
1446 >                if (modCount != expectedModCount)
1447                      throw new ConcurrentModificationException();
1448                  return true;
1449              }
# Line 1455 | Line 1452 | public class Vector<E>
1452  
1453          @SuppressWarnings("unchecked")
1454          public void forEachRemaining(Consumer<? super E> action) {
1458            int i, hi; // hoist accesses and checks from loop
1459            Vector<E> lst; Object[] a;
1455              if (action == null)
1456                  throw new NullPointerException();
1457 <            if ((lst = list) != null) {
1458 <                if ((hi = fence) < 0) {
1459 <                    synchronized (lst) {
1460 <                        expectedModCount = lst.modCount;
1461 <                        a = array = lst.elementData;
1462 <                        hi = fence = lst.elementCount;
1463 <                    }
1469 <                }
1470 <                else
1471 <                    a = array;
1472 <                if (a != null && (i = index) >= 0 && (index = hi) <= a.length) {
1473 <                    while (i < hi)
1474 <                        action.accept((E) a[i++]);
1475 <                    if (lst.modCount == expectedModCount)
1476 <                        return;
1477 <                }
1478 <            }
1479 <            throw new ConcurrentModificationException();
1457 >            final int hi = getFence();
1458 >            final Object[] a = array;
1459 >            int i;
1460 >            for (i = index, index = hi; i < hi; i++)
1461 >                action.accept((E) a[i]);
1462 >            if (modCount != expectedModCount)
1463 >                throw new ConcurrentModificationException();
1464          }
1465  
1466          public long estimateSize() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines