do not copy array twice when inserting

This commit is contained in:
2017-11-10 10:42:47 +01:00
parent 88e0179dd5
commit ecf1a62c95

View File

@@ -158,12 +158,11 @@ public final class IntList implements Serializable, Cloneable {
ensureCapacity(values.length); ensureCapacity(values.length);
// TODO do not copy the array twice // move everything after the insert position to make room for the new values
final int[] newData = new int[data.length]; System.arraycopy(data, pos, data, pos + values.length, values.length);
System.arraycopy(data, 0, newData, 0, pos); // insert the new values
System.arraycopy(values, 0, newData, pos, values.length); System.arraycopy(values, 0, data, pos, values.length);
System.arraycopy(data, pos, newData, pos + values.length, index - pos);
data = newData;
index += values.length; index += values.length;
} }