322 |
|
* of its elements are null |
323 |
|
*/ |
324 |
|
public boolean addAll(Collection<? extends E> c) { |
325 |
< |
final int s = size(), needed; |
326 |
< |
if ((needed = s + c.size() - elements.length + 1) > 0) |
325 |
> |
final int s, needed; |
326 |
> |
if ((needed = (s = size()) + c.size() + 1 - elements.length) > 0) |
327 |
|
grow(needed); |
328 |
< |
c.forEach(e -> addLast(e)); |
328 |
> |
c.forEach(this::addLast); |
329 |
|
// checkInvariants(); |
330 |
|
return size() > s; |
331 |
|
} |
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) { |
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(); |