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 |
|
|