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.121 by jsr166, Mon Nov 21 15:30:44 2016 UTC vs.
Revision 1.127 by jsr166, Wed Apr 19 23:45:50 2017 UTC

# Line 117 | Line 117 | public class ArrayDeque<E> extends Abstr
117          if (jump < needed
118              || (newCapacity = (oldCapacity + jump)) - MAX_ARRAY_SIZE > 0)
119              newCapacity = newCapacity(needed, jump);
120 <        elements = Arrays.copyOf(elements, newCapacity);
120 >        final Object[] es = elements = Arrays.copyOf(elements, newCapacity);
121          // Exceptionally, here tail == head needs to be disambiguated
122 <        if (tail < head || (tail == head && elements[head] != null)) {
122 >        if (tail < head || (tail == head && es[head] != null)) {
123              // wrap around; slide first leg forward to end of array
124              int newSpace = newCapacity - oldCapacity;
125 <            System.arraycopy(elements, head,
126 <                             elements, head + newSpace,
125 >            System.arraycopy(es, head,
126 >                             es, head + newSpace,
127                               oldCapacity - head);
128 <            Arrays.fill(elements, head, head + newSpace, null);
129 <            head += newSpace;
128 >            for (int i = head, to = (head += newSpace); i < to; i++)
129 >                es[i] = null;
130          }
131          // checkInvariants();
132      }
# Line 235 | Line 235 | public class ArrayDeque<E> extends Abstr
235       * @return index 0 <= i < modulus
236       */
237      static final int add(int i, int distance, int modulus) {
238 <        if ((i += distance) - modulus >= 0) distance -= modulus;
238 >        if ((i += distance) - modulus >= 0) i -= modulus;
239          return i;
240      }
241  
# Line 520 | Line 520 | public class ArrayDeque<E> extends Abstr
520      /**
521       * Retrieves and removes the head of the queue represented by this deque.
522       *
523 <     * This method differs from {@link #poll poll} only in that it throws an
524 <     * exception if this deque is empty.
523 >     * This method differs from {@link #poll() poll()} only in that it
524 >     * throws an exception if this deque is empty.
525       *
526       * <p>This method is equivalent to {@link #removeFirst}.
527       *
# 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 822 | Line 820 | public class ArrayDeque<E> extends Abstr
820  
821          /** Constructs spliterator over the given range. */
822          DeqSpliterator(int origin, int fence) {
823 +            // assert 0 <= origin && origin < elements.length;
824 +            // assert 0 <= fence && fence < elements.length;
825              this.cursor = origin;
826              this.fence = fence;
827          }
# Line 888 | Line 888 | public class ArrayDeque<E> extends Abstr
888          }
889      }
890  
891 +    /**
892 +     * @throws NullPointerException {@inheritDoc}
893 +     */
894      public void forEach(Consumer<? super E> action) {
895          Objects.requireNonNull(action);
896          final Object[] es = elements;
# Line 1076 | Line 1079 | public class ArrayDeque<E> extends Abstr
1079  
1080      /**
1081       * Nulls out slots starting at array index i, upto index end.
1082 +     * Condition i == end means "empty" - nothing to do.
1083       */
1084      private static void circularClear(Object[] es, int i, int end) {
1085 +        // assert 0 <= i && i < es.length;
1086 +        // assert 0 <= end && end < es.length;
1087          for (int to = (i <= end) ? end : es.length;
1088               ; i = 0, to = end) {
1089 <            Arrays.fill(es, i, to, null);
1089 >            for (; i < to; i++) es[i] = null;
1090              if (to == end) break;
1091          }
1092      }
# Line 1244 | Line 1250 | public class ArrayDeque<E> extends Abstr
1250          // head == tail disambiguates to "empty".
1251          try {
1252              int capacity = elements.length;
1253 <            // assert head >= 0 && head < capacity;
1254 <            // assert tail >= 0 && tail < capacity;
1253 >            // assert 0 <= head && head < capacity;
1254 >            // assert 0 <= tail && tail < capacity;
1255              // assert capacity > 0;
1256              // assert size() < capacity;
1257              // assert head == tail || elements[head] != null;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines