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.117 by jsr166, Sun Nov 20 06:42:41 2016 UTC vs.
Revision 1.119 by jsr166, Sun Nov 20 08:30:56 2016 UTC

# Line 616 | Line 616 | public class ArrayDeque<E> extends Abstr
616          // checkInvariants();
617          final Object[] es = elements;
618          final int capacity = es.length;
619 <        final int h = head;
619 >        final int h, t;
620          // number of elements before to-be-deleted elt
621 <        final int front = sub(i, h, capacity);
622 <        final int back = size() - front - 1; // number of elements after
621 >        final int front = sub(i, h = head, capacity);
622 >        // number of elements after to-be-deleted elt
623 >        final int back = sub(t = tail, i, capacity) - 1;
624          if (front < back) {
625              // move front elements forwards
626              if (h <= i) {
# Line 635 | Line 636 | public class ArrayDeque<E> extends Abstr
636              return false;
637          } else {
638              // move back elements backwards
639 <            tail = dec(tail, capacity);
639 >            tail = dec(t, capacity);
640              if (i <= tail) {
641                  System.arraycopy(es, i + 1, es, i, back);
642              } else { // Wrap around
643 <                int firstLeg = capacity - (i + 1);
643 <                System.arraycopy(es, i + 1, es, i, firstLeg);
643 >                System.arraycopy(es, i + 1, es, i, capacity - (i + 1));
644                  es[capacity - 1] = es[0];
645 <                System.arraycopy(es, 1, es, 0, back - firstLeg - 1);
645 >                System.arraycopy(es, 1, es, 0, t - 1);
646              }
647              es[tail] = null;
648              // checkInvariants();
# Line 1104 | Line 1104 | public class ArrayDeque<E> extends Abstr
1104      private <T> T[] toArray(Class<T[]> klazz) {
1105          final Object[] es = elements;
1106          final T[] a;
1107 <        final int size = size(), head = this.head, end;
1108 <        final int len = Math.min(size, es.length - head);
1109 <        if ((end = head + size) >= 0) {
1107 >        final int head = this.head, tail = this.tail, end;
1108 >        if ((end = tail + ((head <= tail) ? 0 : es.length)) >= 0) {
1109              a = Arrays.copyOfRange(es, head, end, klazz);
1110          } else {
1111              // integer overflow!
1112 <            a = Arrays.copyOfRange(es, 0, size, klazz);
1113 <            System.arraycopy(es, head, a, 0, len);
1112 >            a = Arrays.copyOfRange(es, 0, end - head, klazz);
1113 >            System.arraycopy(es, head, a, 0, es.length - head);
1114          }
1115 <        if (tail < head)
1116 <            System.arraycopy(es, 0, a, len, tail);
1115 >        if (end != tail)
1116 >            System.arraycopy(es, 0, a, es.length - head, tail);
1117          return a;
1118      }
1119  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines