mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix capacity calculation in ArrayList and StringBuilder.
See #289 and #290
This commit is contained in:
parent
d982f89ab6
commit
b477a7dcad
|
@ -581,7 +581,10 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
|
||||||
if (buffer.length >= capacity) {
|
if (buffer.length >= capacity) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
buffer = TArrays.copyOf(buffer, capacity * 2 + 1);
|
int newLength = buffer.length < Integer.MAX_VALUE / 2
|
||||||
|
? Math.max(capacity, Math.max(buffer.length * 2, 5))
|
||||||
|
: Integer.MAX_VALUE;
|
||||||
|
buffer = TArrays.copyOf(buffer, newLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trimToSize() {
|
public void trimToSize() {
|
||||||
|
|
|
@ -53,7 +53,10 @@ 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.max(5, array.length / 2));
|
int newLength = array.length < Integer.MAX_VALUE / 2
|
||||||
|
? Math.max(minCapacity, Math.max(array.length * 2, 5))
|
||||||
|
: Integer.MAX_VALUE;
|
||||||
|
array = TArrays.copyOf(array, newLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user