diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-09-28 07:24:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-09-28 09:08:54 +0400 |
commit | a4c3b9229448e93f10a7706800822b1e0119c033 (patch) | |
tree | 7270a0f1596bc5b3f569441664de9f8115ad4818 /source/blender/blenlib/intern/stack.c | |
parent | 99ef213dcbab68debe7047996a2e26380254d093 (diff) |
BLI_Stack add BLI_stack_peek, BLI_stack_discard
also remove own incorrect assert
Diffstat (limited to 'source/blender/blenlib/intern/stack.c')
-rw-r--r-- | source/blender/blenlib/intern/stack.c | 42 |
1 files changed, 25 insertions, 17 deletions
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 |