diff options
| author | 2016-10-22 04:39:47 +0200 | |
|---|---|---|
| committer | 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 @@ | |||
| 21 | #include <string.h> | 21 | #include <string.h> |
| 22 | #include "bytearray.h" | 22 | #include "bytearray.h" |
| 23 | 23 | ||
| 24 | #define PAGE_SIZE 4096 | ||
| 25 | |||
| 24 | bytearray_t *byte_array_new() | 26 | bytearray_t *byte_array_new() |
| 25 | { | 27 | { |
| 26 | bytearray_t *a = (bytearray_t*)malloc(sizeof(bytearray_t)); | 28 | bytearray_t *a = (bytearray_t*)malloc(sizeof(bytearray_t)); |
| 27 | a->data = malloc(256); | 29 | a->capacity = PAGE_SIZE * 8; |
| 30 | a->data = malloc(a->capacity); | ||
| 28 | a->len = 0; | 31 | a->len = 0; |
| 29 | a->capacity = 256; | ||
| 30 | return a; | 32 | return a; |
| 31 | } | 33 | } |
| 32 | 34 | ||
| @@ -44,8 +46,10 @@ void byte_array_append(bytearray_t *ba, void *buf, size_t len) | |||
| 44 | if (!ba || !ba->data || (len <= 0)) return; | 46 | if (!ba || !ba->data || (len <= 0)) return; |
| 45 | size_t remaining = ba->capacity-ba->len; | 47 | size_t remaining = ba->capacity-ba->len; |
| 46 | if (len > remaining) { | 48 | if (len > remaining) { |
| 47 | ba->data = realloc(ba->data, ba->capacity + (len - remaining)); | 49 | size_t needed = len - remaining; |
| 48 | ba->capacity += (len - remaining); | 50 | size_t increase = (needed > PAGE_SIZE) ? (needed+(PAGE_SIZE-1)) & (~(PAGE_SIZE-1)) : PAGE_SIZE; |
| 51 | ba->data = realloc(ba->data, ba->capacity + increase); | ||
| 52 | ba->capacity += increase; | ||
| 49 | } | 53 | } |
| 50 | memcpy(((char*)ba->data) + ba->len, buf, len); | 54 | memcpy(((char*)ba->data) + ba->len, buf, len); |
| 51 | ba->len += len; | 55 | ba->len += len; |
