diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-02-24 17:53:46 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | a307f17f44b461f58441926fcbf87883f17ebe61 (patch) | |
tree | ea03a634f06c33591c8afea5139e7e931d429cf7 /src/buffer.c | |
parent | 12e5135d95dc34fd7f7a7c50d6dbac453f252683 (diff) |
Fixed CHECK_RESULT macro, use scoped allocator
Scoped allocator gives us better performance and cleanup code for error
cases is much cleaner
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 7 |
1 files changed, 5 insertions, 2 deletions
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; } |