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);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user