689 |
|
|
690 |
|
DeqIterator() { cursor = head; } |
691 |
|
|
692 |
< |
void doAdvance() { |
693 |
< |
cursor = inc(cursor, elements.length); |
692 |
> |
int advance(int i, int modulus) { |
693 |
> |
return inc(i, modulus); |
694 |
|
} |
695 |
|
|
696 |
|
void doRemove() { |
708 |
|
throw new NoSuchElementException(); |
709 |
|
E e = checkedElementAt(elements, cursor); |
710 |
|
lastRet = cursor; |
711 |
< |
doAdvance(); |
711 |
> |
cursor = advance(cursor, elements.length); |
712 |
|
remaining--; |
713 |
|
return e; |
714 |
|
} |
724 |
|
Objects.requireNonNull(action); |
725 |
|
final Object[] elements = ArrayDeque.this.elements; |
726 |
|
final int capacity = elements.length; |
727 |
< |
for (; remaining > 0; remaining--) { |
728 |
< |
action.accept(checkedElementAt(elements, cursor)); |
729 |
< |
doAdvance(); |
730 |
< |
} |
727 |
> |
int k = remaining; |
728 |
> |
remaining = 0; |
729 |
> |
for (int i = cursor; --k >= 0; i = advance(i, capacity)) |
730 |
> |
action.accept(checkedElementAt(elements, i)); |
731 |
|
} |
732 |
|
} |
733 |
|
|
734 |
|
private class DescendingIterator extends DeqIterator { |
735 |
|
DescendingIterator() { cursor = tail(); } |
736 |
|
|
737 |
< |
@Override void doAdvance() { |
738 |
< |
cursor = dec(cursor, elements.length); |
737 |
> |
@Override int advance(int i, int modulus) { |
738 |
> |
return dec(i, modulus); |
739 |
|
} |
740 |
|
|
741 |
|
@Override void doRemove() { |
787 |
|
} |
788 |
|
|
789 |
|
public ArrayDequeSpliterator trySplit() { |
790 |
< |
if (remaining() > 1) { |
791 |
< |
int mid = remaining >> 1; |
790 |
> |
final int mid; |
791 |
> |
if ((mid = remaining() >> 1) > 0) { |
792 |
|
int oldCursor = cursor; |
793 |
|
cursor = add(cursor, mid, elements.length); |
794 |
|
remaining -= mid; |
801 |
|
Objects.requireNonNull(action); |
802 |
|
final Object[] elements = ArrayDeque.this.elements; |
803 |
|
final int capacity = elements.length; |
804 |
< |
remaining(); // for the initialization side-effect |
805 |
< |
for (; remaining > 0; cursor = inc(cursor, capacity), remaining--) |
806 |
< |
action.accept(checkedElementAt(elements, cursor)); |
804 |
> |
int k = remaining(); |
805 |
> |
remaining = 0; |
806 |
> |
for (int i = cursor; --k >= 0; i = inc(i, capacity)) |
807 |
> |
action.accept(checkedElementAt(elements, i)); |
808 |
|
} |
809 |
|
|
810 |
|
public boolean tryAdvance(Consumer<? super E> action) { |