diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-02-27 22:26:35 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 76d85a10f6cda93eba29dad5372e8160af7289c8 (patch) | |
tree | cfec3043ec45a5e83494ec109e87c239dad6cc47 /src/buffer.c | |
parent | 8201cd9f40897cf6b8e6973b28a8661108702ab1 (diff) |
Use multiple threads to parse
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/src/buffer.c b/src/buffer.c deleted file mode 100644 index a097cbf..0000000 --- a/src/buffer.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "../include/buffer.h" -#include "../include/alloc.h" -#include "../include/mem.h" -#include "../include/scoped_allocator.h" -#include <assert.h> - -int buffer_init(Buffer *self, struct ScopedAllocator *allocator) { - self->data = NULL; - self->size = 0; - self->capacity = 0; - if(allocator) - return scoped_allocator_add_buffer(allocator, self); - return 0; -} - -static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) { - usize capacity; - void *new_mem; - int alloc_result; - - if(self->capacity >= new_capacity) - return BUFFER_OK; - - capacity = self->capacity; - if(capacity == 0) { - capacity = new_capacity; - } else { - while(capacity < new_capacity) { - capacity *= 1.5; - } - } - - alloc_result = am_realloc(self->data, capacity, &new_mem); - if(alloc_result != ALLOC_OK) - return BUFFER_ALLOC_FAIL; - - self->data = new_mem; - self->capacity = capacity; - return BUFFER_OK; -} - -int buffer_append(Buffer *self, void *data, usize size) { - return_if_error(buffer_ensure_capacity(self, self->size + size)); - am_memcpy(self->data + self->size, data, size); - return BUFFER_OK; -} - -void* buffer_get(Buffer *self, usize index, usize type_size) { - usize real_index; - real_index = index * type_size; - assert(real_index < self->size); - return &self->data[real_index]; -}
\ No newline at end of file |