From a4c3b9229448e93f10a7706800822b1e0119c033 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 28 Sep 2014 13:24:01 +1000 Subject: BLI_Stack add BLI_stack_peek, BLI_stack_discard also remove own incorrect assert --- source/blender/blenlib/intern/stack.c | 42 +++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'source/blender/blenlib/intern/stack.c') diff --git a/source/blender/blenlib/intern/stack.c b/source/blender/blenlib/intern/stack.c index 58029120de9..2d3a2f77a3e 100644 --- a/source/blender/blenlib/intern/stack.c +++ b/source/blender/blenlib/intern/stack.c @@ -48,8 +48,6 @@ ((void)0, (((char *)(_stack)->chunk_curr->data) + \ ((_stack)->elem_size * (_stack)->chunk_index))) -#define IS_POW2(a) (((a) & ((a) - 1)) == 0) - struct StackChunk { struct StackChunk *next; char data[0]; @@ -96,11 +94,6 @@ BLI_Stack *BLI_stack_new_ex(const size_t elem_size, const char *description, /* force init */ stack->chunk_index = stack->chunk_elem_max - 1; - /* ensure we have a correctly rounded size */ - BLI_assert((IS_POW2(stack->elem_size) == 0) || - (IS_POW2((stack->chunk_elem_max * stack->elem_size) + - (sizeof(struct StackChunk) + MEM_SIZE_OVERHEAD)))); - return stack; } @@ -182,6 +175,31 @@ void BLI_stack_pop(BLI_Stack *stack, void *dst) BLI_assert(BLI_stack_is_empty(stack) == false); memcpy(dst, CHUNK_LAST_ELEM(stack), stack->elem_size); + + BLI_stack_discard(stack); +} + +void BLI_stack_pop_n(BLI_Stack *stack, void *dst, unsigned int n) +{ + BLI_assert(n <= BLI_stack_count(stack)); + + while (n--) { + BLI_stack_pop(stack, dst); + dst = (void *)((char *)dst + stack->elem_size); + } +} + +void *BLI_stack_peek(BLI_Stack *stack) +{ + BLI_assert(BLI_stack_is_empty(stack) == false); + + return CHUNK_LAST_ELEM(stack); +} + +void BLI_stack_discard(BLI_Stack *stack) +{ + BLI_assert(BLI_stack_is_empty(stack) == false); + #ifdef USE_TOTELEM stack->totelem--; #endif @@ -198,16 +216,6 @@ void BLI_stack_pop(BLI_Stack *stack, void *dst) } } -void BLI_stack_pop_n(BLI_Stack *stack, void *dst, unsigned int n) -{ - BLI_assert(n <= BLI_stack_count(stack)); - - while (n--) { - BLI_stack_pop(stack, dst); - dst = (void *)((char *)dst + stack->elem_size); - } -} - size_t BLI_stack_count(const BLI_Stack *stack) { #ifdef USE_TOTELEM -- cgit v1.2.3