diff options
author | David Robillard <d@drobilla.net> | 2018-05-12 20:39:23 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-04-13 19:15:32 +0200 |
commit | fea20a9af56d5b7640ced14cde92fe6746291502 (patch) | |
tree | 848c9e3a4e3e33d0b65ef39142d0ff8507af3391 /src/stack.h | |
parent | 29cfc326f8f64d8327597f2218f0caefeed4560f (diff) | |
download | serd-fea20a9af56d5b7640ced14cde92fe6746291502.tar.gz serd-fea20a9af56d5b7640ced14cde92fe6746291502.tar.bz2 serd-fea20a9af56d5b7640ced14cde92fe6746291502.zip |
Use a fixed-size reader stack
This improves performance, and makes the reader more suitable for embedded or
network-facing applications, at the cost of requiring the user to specify a
maximum stack size.
Diffstat (limited to 'src/stack.h')
-rw-r--r-- | src/stack.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/stack.h b/src/stack.h index 9f112b6c..c066a75e 100644 --- a/src/stack.h +++ b/src/stack.h @@ -63,8 +63,7 @@ serd_stack_push(SerdStack* stack, size_t n_bytes) { const size_t new_size = stack->size + n_bytes; if (stack->buf_size < new_size) { - stack->buf_size += (stack->buf_size >> 1); // *= 1.5 - stack->buf = (char*)realloc(stack->buf, stack->buf_size); + return NULL; } char* const ret = (stack->buf + stack->size); stack->size = new_size; @@ -82,12 +81,16 @@ static inline void* serd_stack_push_aligned(SerdStack* stack, size_t n_bytes, size_t align) { // Push one byte to ensure space for a pad count - serd_stack_push(stack, 1); + if (!serd_stack_push(stack, 1)) { + return NULL; + } // Push padding if necessary const uint8_t pad = align - stack->size % align; if (pad > 0) { - serd_stack_push(stack, pad); + if (!serd_stack_push(stack, pad)) { + return NULL; + } } // Set top of stack to pad count so we can properly pop later |