117 |
|
if (jump < needed |
118 |
|
|| (newCapacity = (oldCapacity + jump)) - MAX_ARRAY_SIZE > 0) |
119 |
|
newCapacity = newCapacity(needed, jump); |
120 |
< |
elements = Arrays.copyOf(elements, newCapacity); |
120 |
> |
final Object[] es = elements = Arrays.copyOf(elements, newCapacity); |
121 |
|
// Exceptionally, here tail == head needs to be disambiguated |
122 |
< |
if (tail < head || (tail == head && elements[head] != null)) { |
122 |
> |
if (tail < head || (tail == head && es[head] != null)) { |
123 |
|
// wrap around; slide first leg forward to end of array |
124 |
|
int newSpace = newCapacity - oldCapacity; |
125 |
< |
System.arraycopy(elements, head, |
126 |
< |
elements, head + newSpace, |
125 |
> |
System.arraycopy(es, head, |
126 |
> |
es, head + newSpace, |
127 |
|
oldCapacity - head); |
128 |
< |
Arrays.fill(elements, head, head + newSpace, null); |
129 |
< |
head += newSpace; |
128 |
> |
for (int i = head, to = (head += newSpace); i < to; i++) |
129 |
> |
es[i] = null; |
130 |
|
} |
131 |
|
// checkInvariants(); |
132 |
|
} |
1076 |
|
|
1077 |
|
/** |
1078 |
|
* Nulls out slots starting at array index i, upto index end. |
1079 |
+ |
* Condition i == end means "empty" - nothing to do. |
1080 |
|
*/ |
1081 |
|
private static void circularClear(Object[] es, int i, int end) { |
1082 |
+ |
// assert 0 <= i && i < es.length; |
1083 |
+ |
// assert 0 <= end && end < es.length; |
1084 |
|
for (int to = (i <= end) ? end : es.length; |
1085 |
|
; i = 0, to = end) { |
1086 |
< |
Arrays.fill(es, i, to, null); |
1086 |
> |
for (; i < to; i++) es[i] = null; |
1087 |
|
if (to == end) break; |
1088 |
|
} |
1089 |
|
} |