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.123 by jsr166, Sat Nov 26 14:16:18 2016 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines