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.118 by jsr166, Sun Nov 20 07:24:11 2016 UTC vs.
Revision 1.119 by jsr166, Sun Nov 20 08:30:56 2016 UTC

# 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