allocate only as much as is needed

ensureCapacity would allocate up to 50% too much memory
This commit is contained in:
2017-12-16 14:49:20 +01:00
parent f3cbdda121
commit 5006581cf0

View File

@@ -1065,7 +1065,7 @@ public final class IntList implements Serializable, Cloneable {
// TODO use a more efficient algorithm. Especially the removeIf is too // TODO use a more efficient algorithm. Especially the removeIf is too
// expensive, because of all the method calls // expensive, because of all the method calls
final IntList result; final IntList result;
result = new IntList(); result = new IntList(a.size() + b.size());
result.addAll(a); result.addAll(a);
result.addAll(b); result.addAll(b);
result.sort(); result.sort();