From 392135c7db4d9cb4a14ff5935d7c4c6e21363847 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sat, 22 Oct 2016 04:39:47 +0200 Subject: Remove libxml2 dependency in favor of custom XML parsing --- src/bytearray.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/bytearray.c') 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 #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; -- cgit v1.1-32-gdbae