summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2018-12-10 04:06:19 +0100
committerGravatar Nikias Bassen2018-12-10 04:06:19 +0100
commit5bf95e9a4dcd2c02df7ff5317ea810820c442074 (patch)
tree863619ad303bca0ab8c568060320c423312f8236
parent4de329327ce4aa175e8496d1bff8604bffb6c574 (diff)
downloadlibplist-5bf95e9a4dcd2c02df7ff5317ea810820c442074.tar.gz
libplist-5bf95e9a4dcd2c02df7ff5317ea810820c442074.tar.bz2
xplist: Prevent unnecessary reallocations when writing XML output
-rw-r--r--src/xplist.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/xplist.c b/src/xplist.c
index 29b1284..739b5ab 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -293,7 +293,10 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
293 uint32_t maxread = ((76 - indent*8) / 4) * 3; 293 uint32_t maxread = ((76 - indent*8) / 4) * 3;
294 size_t count = 0; 294 size_t count = 0;
295 size_t b64count = 0; 295 size_t b64count = 0;
296 str_buf_grow(*outbuf, (node_data->length / 3 * 4) + 4 + (((node_data->length / maxread) + 1) * (indent+1))); 296 size_t amount = (node_data->length / 3 * 4) + 4 + (((node_data->length / maxread) + 1) * (indent+1));
297 if ((*outbuf)->len + amount > (*outbuf)->capacity) {
298 str_buf_grow(*outbuf, amount);
299 }
297 while (j < node_data->length) { 300 while (j < node_data->length) {
298 for (i = 0; i < indent; i++) { 301 for (i = 0; i < indent; i++) {
299 str_buf_append(*outbuf, "\t", 1); 302 str_buf_append(*outbuf, "\t", 1);