mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Use max() instead of min() when enlarging the array.
Adding n elements subsequently has now an O(n) running time while it was O(n^2) before.
This commit is contained in:
parent
9d2e9d7911
commit
b03ba67a88
|
@ -53,7 +53,7 @@ public class TArrayList<E> extends TAbstractList<E> implements TCloneable, TSeri
|
||||||
|
|
||||||
public void ensureCapacity(int minCapacity) {
|
public void ensureCapacity(int minCapacity) {
|
||||||
if (array.length < minCapacity) {
|
if (array.length < minCapacity) {
|
||||||
array = TArrays.copyOf(array, array.length + TMath.min(5, array.length / 2));
|
array = TArrays.copyOf(array, array.length + TMath.max(5, array.length / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user