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.37 by jsr166, Wed Nov 30 03:31:47 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 1456 | Line 1453 | public class Vector<E>
1453          @SuppressWarnings("unchecked")
1454          public void forEachRemaining(Consumer<? super E> action) {
1455              int i, hi; // hoist accesses and checks from loop
1456 <            Vector<E> lst; Object[] a;
1456 >            Object[] a;
1457              if (action == null)
1458                  throw new NullPointerException();
1459 <            if ((lst = list) != null) {
1460 <                if ((hi = fence) < 0) {
1461 <                    synchronized (lst) {
1462 <                        expectedModCount = lst.modCount;
1463 <                        a = array = lst.elementData;
1467 <                        hi = fence = lst.elementCount;
1468 <                    }
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;
1459 >            if ((hi = fence) < 0) {
1460 >                synchronized (Vector.this) {
1461 >                    expectedModCount = modCount;
1462 >                    a = array = elementData;
1463 >                    hi = fence = elementCount;
1464                  }
1465              }
1466 +            else
1467 +                a = array;
1468 +            if (a != null && (i = index) >= 0 && (index = hi) <= a.length) {
1469 +                while (i < hi)
1470 +                    action.accept((E) a[i++]);
1471 +                if (modCount == expectedModCount)
1472 +                    return;
1473 +            }
1474              throw new ConcurrentModificationException();
1475          }
1476  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines