From a307f17f44b461f58441926fcbf87883f17ebe61 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 24 Feb 2019 17:53:46 +0100 Subject: Fixed CHECK_RESULT macro, use scoped allocator Scoped allocator gives us better performance and cleanup code for error cases is much cleaner --- src/buffer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 84fb5fa..972e23a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -16,10 +16,12 @@ void buffer_deinit(Buffer *self) { self->capacity = 0; } -static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) { +static CHECK_RESULT int buffer_ensure_capacity_for(Buffer *self, usize size) { usize capacity; void *new_mem; int alloc_result; + usize new_capacity; + new_capacity = self->size + size; if(self->capacity >= new_capacity) return BUFFER_OK; @@ -43,8 +45,9 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) } int buffer_append(Buffer *self, void *data, usize size) { - return_if_error(buffer_ensure_capacity(self, self->size + size)); + return_if_error(buffer_ensure_capacity_for(self, size)); am_memcpy(self->data + self->size, data, size); + self->size += size; return BUFFER_OK; } -- cgit v1.2.3