263 |
|
public void addFirst(E e) { |
264 |
|
// checkInvariants(); |
265 |
|
Objects.requireNonNull(e); |
266 |
< |
Object[] elements; |
267 |
< |
int capacity, s = size; |
268 |
< |
while (s == (capacity = (elements = this.elements).length)) |
269 |
< |
grow(1); |
270 |
< |
elements[head = dec(head, capacity)] = e; |
266 |
> |
final Object[] elements; |
267 |
> |
final int capacity, s; |
268 |
> |
if ((s = size) == (capacity = (elements = this.elements).length)) |
269 |
> |
addFirstSlowPath(e); |
270 |
> |
else |
271 |
> |
elements[head = dec(head, capacity)] = e; |
272 |
|
size = s + 1; |
273 |
|
} |
274 |
|
|
275 |
+ |
private void addFirstSlowPath(E e) { |
276 |
+ |
grow(1); |
277 |
+ |
final Object[] elements = this.elements; |
278 |
+ |
elements[head = dec(head, elements.length)] = e; |
279 |
+ |
// checkInvariants(); |
280 |
+ |
} |
281 |
+ |
|
282 |
|
/** |
283 |
|
* Inserts the specified element at the end of this deque. |
284 |
|
* |
290 |
|
public void addLast(E e) { |
291 |
|
// checkInvariants(); |
292 |
|
Objects.requireNonNull(e); |
293 |
< |
Object[] elements; |
294 |
< |
int capacity, s = size; |
295 |
< |
while (s == (capacity = (elements = this.elements).length)) |
296 |
< |
grow(1); |
297 |
< |
elements[add(head, s, capacity)] = e; |
293 |
> |
final Object[] elements; |
294 |
> |
final int capacity, s; |
295 |
> |
if ((s = size) == (capacity = (elements = this.elements).length)) |
296 |
> |
addLastSlowPath(e); |
297 |
> |
else |
298 |
> |
elements[add(head, s, capacity)] = e; |
299 |
|
size = s + 1; |
300 |
|
} |
301 |
|
|
302 |
+ |
private void addLastSlowPath(E e) { |
303 |
+ |
grow(1); |
304 |
+ |
final Object[] elements = this.elements; |
305 |
+ |
elements[add(head, size, elements.length)] = e; |
306 |
+ |
// checkInvariants(); |
307 |
+ |
} |
308 |
+ |
|
309 |
|
/** |
310 |
|
* Adds all of the elements in the specified collection at the end |
311 |
|
* of this deque, as if by calling {@link #addLast} on each one, |