diff --git a/gson/src/main/java/com/google/gson/JsonArray.java b/gson/src/main/java/com/google/gson/JsonArray.java index 19299d14..96fe23ed 100644 --- a/gson/src/main/java/com/google/gson/JsonArray.java +++ b/gson/src/main/java/com/google/gson/JsonArray.java @@ -39,14 +39,21 @@ public final class JsonArray extends JsonElement implements Iterable(); } + + public JsonArray(int capacity) { + elements = new ArrayList(capacity); + } @Override JsonArray deepCopy() { - JsonArray result = new JsonArray(); - for (JsonElement element : elements) { - result.add(element.deepCopy()); + if (!elements.isEmpty()) { + JsonArray result = new JsonArray(elements.size()); + for (JsonElement element : elements) { + result.add(element.deepCopy()); + } + return result; } - return result; + return new JsonArray(); } /**