mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-06 18:55:30 +08:00
Increase array list capacity in addAll method to ensure it can hold additional elements.
This commit is contained in:
@@ -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)));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user