summaryrefslogtreecommitdiffstats
path: root/src/bytearray.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2018-12-10 01:40:56 +0100
committerGravatar Nikias Bassen2018-12-10 01:40:56 +0100
commit71dd25e14616bd261c3b6c80ff990cd1078266f6 (patch)
tree1d95c664a9bd18eb49604fb92fe0e0be3fa0969e /src/bytearray.c
parentaf994607c799f3bfcbab280ef97e3bd85fe69ed2 (diff)
downloadlibplist-71dd25e14616bd261c3b6c80ff990cd1078266f6.tar.gz
libplist-71dd25e14616bd261c3b6c80ff990cd1078266f6.tar.bz2
bplist: Improve performance and memory usage when writing binary plist
Diffstat (limited to 'src/bytearray.c')
-rw-r--r--src/bytearray.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/bytearray.c b/src/bytearray.c
index fff5089..7d0549b 100644
--- a/src/bytearray.c
+++ b/src/bytearray.c
@@ -23,10 +23,10 @@
#define PAGE_SIZE 4096
-bytearray_t *byte_array_new()
+bytearray_t *byte_array_new(size_t initial)
{
bytearray_t *a = (bytearray_t*)malloc(sizeof(bytearray_t));
- a->capacity = PAGE_SIZE * 8;
+ a->capacity = (initial > PAGE_SIZE) ? (initial+(PAGE_SIZE-1)) & (~(PAGE_SIZE-1)) : PAGE_SIZE;
a->data = malloc(a->capacity);
a->len = 0;
return a;