From b03ba67a884a0e14db7bb5dbf678cb9c8b2223a1 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Thu, 18 Aug 2016 20:09:48 +0200 Subject: [PATCH] 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. --- .../src/main/java/org/teavm/classlib/java/util/TArrayList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java index e72dbe8e7..7c02f3a25 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java @@ -53,7 +53,7 @@ public class TArrayList extends TAbstractList implements TCloneable, TSeri public void ensureCapacity(int 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)); } }