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.95 by jsr166, Sat Oct 29 19:10:27 2016 UTC vs.
Revision 1.98 by jsr166, Sat Oct 29 22:47:55 2016 UTC

# Line 243 | Line 243 | public class ArrayDeque<E> extends Abstr
243       * but does catch ones that corrupt traversal.  It's a little
244       * surprising that javac allows this abuse of generics.
245       */
246 <    static final <E> E nonNullElementAt(Object[] elements, int i) {
247 <        @SuppressWarnings("unchecked") E e = (E) elements[i];
246 >    static final <E> E nonNullElementAt(Object[] es, int i) {
247 >        @SuppressWarnings("unchecked") E e = (E) es[i];
248          if (e == null)
249              throw new ConcurrentModificationException();
250          return e;
# Line 731 | Line 731 | public class ArrayDeque<E> extends Abstr
731          }
732  
733          public void forEachRemaining(Consumer<? super E> action) {
734 +            Objects.requireNonNull(action);
735              final int k;
736              if ((k = remaining) > 0) {
737                  remaining = 0;
# Line 761 | Line 762 | public class ArrayDeque<E> extends Abstr
762          }
763  
764          public final void forEachRemaining(Consumer<? super E> action) {
765 +            Objects.requireNonNull(action);
766              final int k;
767              if ((k = remaining) > 0) {
768                  remaining = 0;
769 <                forEachRemainingDescending(action, elements, cursor, k);
769 >                final Object[] elements = ArrayDeque.this.elements;
770 >                int i, end, to, todo;
771 >                todo = (to = ((end = (i = cursor) - k) >= -1) ? end : -1) - end;
772 >                for (;; to = (i = elements.length - 1) - todo, todo = 0) {
773 >                    for (; i > to; i--)
774 >                        action.accept(nonNullElementAt(elements, i));
775 >                    if (todo == 0) break;
776 >                }
777                  if ((lastRet = cursor - (k - 1)) < 0)
778                      lastRet += elements.length;
779              }
# Line 824 | Line 833 | public class ArrayDeque<E> extends Abstr
833          }
834  
835          public void forEachRemaining(Consumer<? super E> action) {
836 +            Objects.requireNonNull(action);
837              final int k = remaining(); // side effect!
838              remaining = 0;
839              ArrayDeque.forEachRemaining(action, elements, cursor, k);
# Line 874 | Line 884 | public class ArrayDeque<E> extends Abstr
884       * checks for concurrent modification, for use in iterators.
885       */
886      static <E> void forEachRemaining(
887 <        Consumer<? super E> action, Object[] elements, int i, int remaining) {
888 <        Objects.requireNonNull(action);
879 <        final int capacity = elements.length;
887 >        Consumer<? super E> action, Object[] es, int i, int remaining) {
888 >        final int capacity = es.length;
889          int end, to, todo;
890          todo = (end = i + remaining)
891              - (to = (capacity - end >= 0) ? end : capacity);
892          for (;; to = todo, i = 0, todo = 0) {
893              for (; i < to; i++)
894 <                action.accept(nonNullElementAt(elements, i));
886 <            if (todo == 0) break;
887 <        }
888 <    }
889 <
890 <    static <E> void forEachRemainingDescending(
891 <        Consumer<? super E> action, Object[] elements, int i, int remaining) {
892 <        Objects.requireNonNull(action);
893 <        final int capacity = elements.length;
894 <        int end, to, todo;
895 <        todo = (to = ((end = i - remaining) >= -1) ? end : -1) - end;
896 <        for (;; to = (i = capacity - 1) - todo, todo = 0) {
897 <            for (; i > to; i--)
898 <                action.accept(nonNullElementAt(elements, i));
894 >                action.accept(nonNullElementAt(es, i));
895              if (todo == 0) break;
896          }
897      }
# Line 1035 | Line 1031 | public class ArrayDeque<E> extends Abstr
1031      /**
1032       * Nulls out count elements, starting at array index from.
1033       */
1034 <    private static void clearSlice(Object[] elements, int from, int count) {
1035 <        final int capacity = elements.length, end = from + count;
1034 >    private static void clearSlice(Object[] es, int from, int count) {
1035 >        final int capacity = es.length, end = from + count;
1036          final int leg = (capacity - end >= 0) ? end : capacity;
1037 <        Arrays.fill(elements, from, leg, null);
1037 >        Arrays.fill(es, from, leg, null);
1038          if (leg != end)
1039 <            Arrays.fill(elements, 0, end - capacity, null);
1039 >            Arrays.fill(es, 0, end - capacity, null);
1040      }
1041  
1042      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines