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

Method growForInsert

vm/JavaAPI/src/java/util/ArrayList.java:393–416  ·  view source on GitHub ↗
(int location, int required)

Source from the content-addressed store, hash-verified

391 }
392
393 private void growForInsert(int location, int required) {
394 // REVIEW: we grow too quickly because we are called with the
395 // size of the new collection to add without taking in
396 // to account the free space we already have
397 int increment = size / 2;
398 if (required > increment) {
399 increment = required;
400 }
401 if (increment < 12) {
402 increment = 12;
403 }
404 E[] newArray = newElementArray(size + increment);
405 // REVIEW: biased towards leaving space at the beginning?
406 // perhaps newFirst should be (increment-required)/2?
407 int newFirst = increment - required;
408 // Copy elements after location to the new array skipping inserted
409 // elements
410 System.arraycopy(array, location + firstIndex, newArray, newFirst
411 + location + required, size - location);
412 // Copy elements before location to the new array from firstIndex
413 System.arraycopy(array, firstIndex, newArray, newFirst, location);
414 firstIndex = newFirst;
415 array = newArray;
416 }
417
418 @Override
419 public int indexOf(Object object) {

Callers 2

addMethod · 0.95
addAllMethod · 0.95

Calls 2

newElementArrayMethod · 0.95
arraycopyMethod · 0.95

Tested by

no test coverage detected