ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentLinkedDeque.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentLinkedDeque.java (file contents):
Revision 1.84 by jsr166, Mon Dec 26 17:29:34 2016 UTC vs.
Revision 1.85 by jsr166, Mon Dec 26 19:54:45 2016 UTC

# Line 1387 | Line 1387 | public class ConcurrentLinkedDeque<E>
1387          boolean exhausted;  // true when no more nodes
1388  
1389          public Spliterator<E> trySplit() {
1390 <            Node<E> p;
1391 <            int b = batch;
1392 <            int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1;
1393 <            if (!exhausted &&
1394 <                ((p = current) != null || (p = first()) != null)) {
1395 <                if (p.item == null && p == (p = p.next))
1396 <                    current = p = first();
1397 <                if (p != null && p.next != null) {
1398 <                    Object[] a = new Object[n];
1399 <                    int i = 0;
1400 <                    do {
1401 <                        if ((a[i] = p.item) != null)
1402 <                            ++i;
1403 <                        if (p == (p = p.next))
1404 <                            p = first();
1405 <                    } while (p != null && i < n);
1406 <                    if ((current = p) == null)
1407 <                        exhausted = true;
1408 <                    if (i > 0) {
1409 <                        batch = i;
1410 <                        return Spliterators.spliterator
1411 <                            (a, 0, i, (Spliterator.ORDERED |
1412 <                                       Spliterator.NONNULL |
1413 <                                       Spliterator.CONCURRENT));
1414 <                    }
1415 <                }
1416 <            }
1417 <            return null;
1390 >            Node<E> p, q;
1391 >            if ((p = current()) == null || (q = p.next) == null)
1392 >                return null;
1393 >            int i = 0, n = batch = Math.min(batch + 1, MAX_BATCH);
1394 >            Object[] a = null;
1395 >            do {
1396 >                final E e;
1397 >                if ((e = p.item) != null)
1398 >                    ((a != null) ? a : (a = new Object[n]))[i++] = e;
1399 >                if (p == (p = q))
1400 >                    p = first();
1401 >            } while (p != null && (q = p.next) != null && i < n);
1402 >            setCurrent(p);
1403 >            return (i == 0) ? null :
1404 >                Spliterators.spliterator(a, 0, i, (Spliterator.ORDERED |
1405 >                                                   Spliterator.NONNULL |
1406 >                                                   Spliterator.CONCURRENT));
1407          }
1408  
1409          public void forEachRemaining(Consumer<? super E> action) {
1410              Objects.requireNonNull(action);
1411              Node<E> p;
1412 <            if (!exhausted &&
1424 <                ((p = current) != null || (p = first()) != null)) {
1412 >            if ((p = current()) != null) {
1413                  current = null;
1414                  exhausted = true;
1415                  do {
1416 <                    E e = p.item;
1416 >                    final E e;
1417 >                    if ((e = p.item) != null)
1418 >                        action.accept(e);
1419                      if (p == (p = p.next))
1420                          p = first();
1431                    if (e != null)
1432                        action.accept(e);
1421                  } while (p != null);
1422              }
1423          }
# Line 1437 | Line 1425 | public class ConcurrentLinkedDeque<E>
1425          public boolean tryAdvance(Consumer<? super E> action) {
1426              Objects.requireNonNull(action);
1427              Node<E> p;
1428 <            if (!exhausted &&
1441 <                ((p = current) != null || (p = first()) != null)) {
1428 >            if ((p = current()) != null) {
1429                  E e;
1430                  do {
1431                      e = p.item;
1432                      if (p == (p = p.next))
1433                          p = first();
1434                  } while (e == null && p != null);
1435 <                if ((current = p) == null)
1449 <                    exhausted = true;
1435 >                setCurrent(p);
1436                  if (e != null) {
1437                      action.accept(e);
1438                      return true;
# Line 1455 | Line 1441 | public class ConcurrentLinkedDeque<E>
1441              return false;
1442          }
1443  
1444 +        private void setCurrent(Node<E> p) {
1445 +            if ((current = p) == null)
1446 +                exhausted = true;
1447 +        }
1448 +
1449 +        private Node<E> current() {
1450 +            Node<E> p;
1451 +            if ((p = current) == null && !exhausted)
1452 +                setCurrent(p = first());
1453 +            return p;
1454 +        }
1455 +
1456          public long estimateSize() { return Long.MAX_VALUE; }
1457  
1458          public int characteristics() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines