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.101 by jsr166, Sun Oct 30 19:34:36 2016 UTC vs.
Revision 1.102 by jsr166, Sun Oct 30 20:10:34 2016 UTC

# Line 1055 | Line 1055 | public class ArrayDeque<E> extends Abstr
1055  
1056      private <T> T[] toArray(Class<T[]> klazz) {
1057          final Object[] es = elements;
1058        final int capacity = es.length;
1059        final int head = this.head, end = head + size;
1058          final T[] a;
1059 <        if (end >= 0) {
1059 >        final int head, len, end, todo;
1060 >        todo = size - (len = Math.min(size, es.length - (head = this.head)));
1061 >        if ((end = head + size) >= 0) {
1062              a = Arrays.copyOfRange(es, head, end, klazz);
1063          } else {
1064              // integer overflow!
1065              a = Arrays.copyOfRange(es, 0, size, klazz);
1066 <            System.arraycopy(es, head, a, 0, capacity - head);
1066 >            System.arraycopy(es, head, a, 0, len);
1067          }
1068 <        if (end - capacity > 0)
1069 <            System.arraycopy(es, 0, a, capacity - head, end - capacity);
1068 >        if (todo > 0)
1069 >            System.arraycopy(es, 0, a, len, todo);
1070          return a;
1071      }
1072  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines