--- jsr166/src/main/java/util/ArrayDeque.java 2016/11/05 00:25:44 1.106 +++ jsr166/src/main/java/util/ArrayDeque.java 2016/11/05 16:21:06 1.109 @@ -244,14 +244,6 @@ public class ArrayDeque extends Abstr } /** - * Returns the array index of the last element. - * May return invalid index -1 if there are no elements. - */ - final int last() { - return dec(tail, elements.length); - } - - /** * Returns element at array index i. * This is a slight abuse of generics, accepted by javac. */ @@ -475,9 +467,9 @@ public class ArrayDeque extends Abstr public boolean removeLastOccurrence(Object o) { if (o != null) { final Object[] es = elements; - for (int i = last(), end = head - 1, to = (i >= end) ? end : -1; - ; i = es.length - 1, to = end) { - for (; i > to; i--) + for (int i = tail, end = head, to = (i >= end) ? end : 0; + ; i = es.length, to = end) { + while (--i >= to) if (o.equals(es[i])) { delete(i); return true; @@ -752,7 +744,7 @@ public class ArrayDeque extends Abstr } private class DescendingIterator extends DeqIterator { - DescendingIterator() { cursor = last(); } + DescendingIterator() { cursor = dec(tail, elements.length); } public final E next() { if (remaining <= 0) @@ -779,12 +771,12 @@ public class ArrayDeque extends Abstr final Object[] es = elements; if (es[cursor] == null || sub(cursor, head, es.length) + 1 != r) throw new ConcurrentModificationException(); - for (int i = cursor, end = head - 1, to = (i >= end) ? end : -1; + for (int i = cursor, end = head, to = (i >= end) ? end : 0; ; i = es.length - 1, to = end) { - for (; i > to; i--) + for (; i >= to; i--) action.accept(elementAt(es, i)); if (to == end) { - if (end != head - 1) + if (end != head) throw new ConcurrentModificationException(); lastRet = head; break;