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

Comparing jsr166/src/main/java/util/ArrayDeque.java (file contents):
Revision 1.118 by jsr166, Sun Nov 20 07:24:11 2016 UTC vs.
Revision 1.121 by jsr166, Mon Nov 21 15:30:44 2016 UTC

# Line 864 | Line 864 | public class ArrayDeque<E> extends Abstr
864          }
865  
866          public boolean tryAdvance(Consumer<? super E> action) {
867 <            if (action == null)
868 <                throw new NullPointerException();
869 <            final int t, i;
870 <            if ((t = getFence()) == (i = cursor))
871 <                return false;
867 >            Objects.requireNonNull(action);
868              final Object[] es = elements;
869 +            if (fence < 0) { fence = tail; cursor = head; } // late-binding
870 +            final int i;
871 +            if ((i = cursor) == fence)
872 +                return false;
873 +            E e = nonNullElementAt(es, i);
874              cursor = inc(i, es.length);
875 <            action.accept(nonNullElementAt(es, i));
875 >            action.accept(e);
876              return true;
877          }
878  
# Line 1104 | Line 1105 | public class ArrayDeque<E> extends Abstr
1105      private <T> T[] toArray(Class<T[]> klazz) {
1106          final Object[] es = elements;
1107          final T[] a;
1108 <        final int size = size(), head = this.head, end;
1109 <        final int len = Math.min(size, es.length - head);
1110 <        if ((end = head + size) >= 0) {
1108 >        final int head = this.head, tail = this.tail, end;
1109 >        if ((end = tail + ((head <= tail) ? 0 : es.length)) >= 0) {
1110 >            // Uses null extension feature of copyOfRange
1111              a = Arrays.copyOfRange(es, head, end, klazz);
1112          } else {
1113              // integer overflow!
1114 <            a = Arrays.copyOfRange(es, 0, size, klazz);
1115 <            System.arraycopy(es, head, a, 0, len);
1114 >            a = Arrays.copyOfRange(es, 0, end - head, klazz);
1115 >            System.arraycopy(es, head, a, 0, es.length - head);
1116          }
1117 <        if (tail < head)
1118 <            System.arraycopy(es, 0, a, len, tail);
1117 >        if (end != tail)
1118 >            System.arraycopy(es, 0, a, es.length - head, tail);
1119          return a;
1120      }
1121  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines