MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / growAtFront

Method growAtFront

vm/JavaAPI/src/java/util/ArrayList.java:364–391  ·  view source on GitHub ↗
(int required)

Source from the content-addressed store, hash-verified

362 }
363
364 private void growAtFront(int required) {
365 if (array.length - size >= required) {
366 int newFirst = array.length - size;
367 // REVIEW: as growAtEnd, why not move size == 0 out as
368 // special case
369 if (size != 0) {
370 System.arraycopy(array, firstIndex, array, newFirst, size);
371 int lastIndex = firstIndex + size;
372 int length = lastIndex > newFirst ? newFirst : lastIndex;
373 Arrays.fill(array, firstIndex, length, null);
374 }
375 firstIndex = newFirst;
376 } else {
377 int increment = size / 2;
378 if (required > increment) {
379 increment = required;
380 }
381 if (increment < 12) {
382 increment = 12;
383 }
384 E[] newArray = newElementArray(size + increment);
385 if (size != 0) {
386 System.arraycopy(array, firstIndex, newArray, increment, size);
387 }
388 firstIndex = newArray.length - size;
389 array = newArray;
390 }
391 }
392
393 private void growForInsert(int location, int required) {
394 // REVIEW: we grow too quickly because we are called with the

Callers 3

addMethod · 0.95
addAllMethod · 0.95
ensureCapacityMethod · 0.95

Calls 3

arraycopyMethod · 0.95
fillMethod · 0.95
newElementArrayMethod · 0.95

Tested by

no test coverage detected