do not copy array twice when inserting
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user