mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-10 12:34:30 +08:00
#863 compute initial capacity for StringBuilderWriter
This commit is contained in:
@@ -1694,7 +1694,10 @@ public class JSONArray implements Iterable<Object> {
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public String toString(int indentFactor) throws JSONException {
|
||||
Writer sw = new StringBuilderWriter();
|
||||
// each value requires a comma, so multiply the count my 2
|
||||
// We don't want to oversize the initial capacity
|
||||
int initialSize = myArrayList.size() * 2;
|
||||
Writer sw = new StringBuilderWriter(Math.max(initialSize, 16));
|
||||
return this.write(sw, indentFactor, 0).toString();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user