summaryrefslogtreecommitdiffstats
path: root/src/xplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2017-02-15 15:14:12 +0100
committerGravatar Nikias Bassen2017-02-15 15:14:12 +0100
commit8ad21e6b59e5e5a3104660f17ad2b0e9122edecf (patch)
tree0d39423c866b90854618c28eb7a8f312374bdb4e /src/xplist.c
parent32ee5213fe64f1e10ec76c1ee861ee6f233120dd (diff)
downloadlibplist-8ad21e6b59e5e5a3104660f17ad2b0e9122edecf.tar.gz
libplist-8ad21e6b59e5e5a3104660f17ad2b0e9122edecf.tar.bz2
xplist: Improve writing of large PLIST_DATA nodes by growing buffer in advance
Instead of letting the buffer grow by just the amount of bytes currently transformed to base64 - which is basically line by line - we now calculate the size of the output blob in advance and grow the buffer accordingly. This will reduce the amount of reallocs to just one, which is especially important for large data blobs. While this is a general improvement for all platforms, it is on platforms like Windows where realloc() can be REALLY slow; converting a 20mb blob to XML can easily take up to a minute (due to the several hundred thousand calls to realloc()). With this commit, it will be fast again.
Diffstat (limited to 'src/xplist.c')
-rw-r--r--src/xplist.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/xplist.c b/src/xplist.c
index 0e9b007..7f20ef2 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -294,6 +294,7 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
uint32_t maxread = ((76 - indent*8) / 4) * 3;
size_t count = 0;
size_t b64count = 0;
+ str_buf_grow(*outbuf, (node_data->length / 3 * 4) + 4 + (((node_data->length / maxread) + 1) * (indent+1)));
while (j < node_data->length) {
for (i = 0; i < indent; i++) {
str_buf_append(*outbuf, "\t", 1);