1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Increase array list capacity in addAll method to ensure it can hold additional elements.

This commit is contained in:
Erik C. Thauvin 2020-07-21 17:11:24 -07:00
parent aa0a5a7245
commit 86e136afc9

View file

@ -1548,7 +1548,7 @@ public class JSONArray implements Iterable<Object> {
private void addAll(Object array) throws JSONException { private void addAll(Object array) throws JSONException {
if (array.getClass().isArray()) { if (array.getClass().isArray()) {
int length = Array.getLength(array); int length = Array.getLength(array);
this.myArrayList.ensureCapacity(length); this.myArrayList.ensureCapacity(this.myArrayList.size() + length);
for (int i = 0; i < length; i += 1) { for (int i = 0; i < length; i += 1) {
this.put(JSONObject.wrap(Array.get(array, i))); this.put(JSONObject.wrap(Array.get(array, i)));
} }