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; |
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 |
|
} |
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); |
885 |
|
*/ |
886 |
|
static <E> void forEachRemaining( |
887 |
|
Consumer<? super E> action, Object[] es, int i, int remaining) { |
878 |
– |
Objects.requireNonNull(action); |
888 |
|
final int capacity = es.length; |
889 |
|
int end, to, todo; |
890 |
|
todo = (end = i + remaining) |
894 |
|
action.accept(nonNullElementAt(es, i)); |
895 |
|
if (todo == 0) break; |
896 |
|
} |
888 |
– |
} |
889 |
– |
|
890 |
– |
static <E> void forEachRemainingDescending( |
891 |
– |
Consumer<? super E> action, Object[] es, int i, int remaining) { |
892 |
– |
Objects.requireNonNull(action); |
893 |
– |
final int capacity = es.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(es, i)); |
899 |
– |
if (todo == 0) break; |
900 |
– |
} |
897 |
|
} |
898 |
|
|
899 |
|
/** |