MCPcopy Index your code
hub / github.com/davidgiven/luje / growAtFront

Method growAtFront

lib/java/util/ArrayList.java:378–405  ·  view source on GitHub ↗
(int required)

Source from the content-addressed store, hash-verified

376 }
377
378 private void growAtFront(int required) {
379 if (array.length - size >= required) {
380 int newFirst = array.length - size;
381 // REVIEW: as growAtEnd, why not move size == 0 out as
382 // special case
383 if (size != 0) {
384 System.arraycopy(array, firstIndex, array, newFirst, size);
385 int lastIndex = firstIndex + size;
386 int length = lastIndex > newFirst ? newFirst : lastIndex;
387 Arrays.fill(array, firstIndex, length, null);
388 }
389 firstIndex = newFirst;
390 } else {
391 int increment = size / 2;
392 if (required > increment) {
393 increment = required;
394 }
395 if (increment < 12) {
396 increment = 12;
397 }
398 E[] newArray = newElementArray(size + increment);
399 if (size != 0) {
400 System.arraycopy(array, firstIndex, newArray, increment, size);
401 }
402 firstIndex = newArray.length - size;
403 array = newArray;
404 }
405 }
406
407 private void growForInsert(int location, int required) {
408 // 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