From 95f7334bbc02f3e75b33b9914eee58c69f1588bd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 May 2018 20:39:23 +0200 Subject: 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. --- src/stack.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/stack.h') diff --git a/src/stack.h b/src/stack.h index 8943370c..174c6378 100644 --- a/src/stack.h +++ b/src/stack.h @@ -66,8 +66,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; @@ -85,12 +84,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 size_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 -- cgit v1.2.1