diff options
author | Nikias Bassen | 2016-10-22 04:39:47 +0200 |
---|---|---|
committer | Nikias Bassen | 2016-10-22 04:39:47 +0200 |
commit | 392135c7db4d9cb4a14ff5935d7c4c6e21363847 (patch) | |
tree | 0e19125ed99b6b2ced754d1b9b3f4bc5245f8c39 /src/bytearray.c | |
parent | a3263ad344ff315ac1cba96f0b84b9afff6da787 (diff) | |
download | libplist-392135c7db4d9cb4a14ff5935d7c4c6e21363847.tar.gz libplist-392135c7db4d9cb4a14ff5935d7c4c6e21363847.tar.bz2 |
Remove libxml2 dependency in favor of custom XML parsing
Diffstat (limited to 'src/bytearray.c')
-rw-r--r-- | src/bytearray.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/bytearray.c b/src/bytearray.c index 2c6ce4a..861890e 100644 --- a/src/bytearray.c +++ b/src/bytearray.c @@ -21,12 +21,14 @@ #include <string.h> #include "bytearray.h" +#define PAGE_SIZE 4096 + bytearray_t *byte_array_new() { bytearray_t *a = (bytearray_t*)malloc(sizeof(bytearray_t)); - a->data = malloc(256); + a->capacity = PAGE_SIZE * 8; + a->data = malloc(a->capacity); a->len = 0; - a->capacity = 256; return a; } @@ -44,8 +46,10 @@ void byte_array_append(bytearray_t *ba, void *buf, size_t len) if (!ba || !ba->data || (len <= 0)) return; size_t remaining = ba->capacity-ba->len; if (len > remaining) { - ba->data = realloc(ba->data, ba->capacity + (len - remaining)); - ba->capacity += (len - remaining); + size_t needed = len - remaining; + size_t increase = (needed > PAGE_SIZE) ? (needed+(PAGE_SIZE-1)) & (~(PAGE_SIZE-1)) : PAGE_SIZE; + ba->data = realloc(ba->data, ba->capacity + increase); + ba->capacity += increase; } memcpy(((char*)ba->data) + ba->len, buf, len); ba->len += len; |