diff --git a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java index 02d7f82..d7baed0 100644 --- a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java +++ b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java @@ -158,12 +158,11 @@ public final class IntList implements Serializable, Cloneable { ensureCapacity(values.length); - // TODO do not copy the array twice - final int[] newData = new int[data.length]; - System.arraycopy(data, 0, newData, 0, pos); - System.arraycopy(values, 0, newData, pos, values.length); - System.arraycopy(data, pos, newData, pos + values.length, index - pos); - data = newData; + // move everything after the insert position to make room for the new values + System.arraycopy(data, pos, data, pos + values.length, values.length); + // insert the new values + System.arraycopy(values, 0, data, pos, values.length); + index += values.length; }