diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-10-01 17:35:17 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-10-01 17:36:29 +0300 |
commit | bdd142bc022b131db7435a9d01ceaf1fdb1d8f24 (patch) | |
tree | b6be39f3800d39c801fa128bb21e956d208a0f9a /source | |
parent | 2bddf44b117b0dc0d2443a0d21ab2d1103e87e5e (diff) |
Cleanup: convert some macros to functions
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/gsqueue.c | 23 | ||||
-rw-r--r-- | source/blender/blenlib/intern/stack.c | 15 |
2 files changed, 20 insertions, 18 deletions
diff --git a/source/blender/blenlib/intern/gsqueue.c b/source/blender/blenlib/intern/gsqueue.c index fed8a7366b6..5e1fbf6eade 100644 --- a/source/blender/blenlib/intern/gsqueue.c +++ b/source/blender/blenlib/intern/gsqueue.c @@ -34,14 +34,6 @@ /* ensure we get at least this many elems per chunk */ #define CHUNK_ELEM_MIN 32 -/* Gets the first or last element in the queue */ -#define CHUNK_FIRST_ELEM(_queue) \ - ((void)0, \ - (((char *)(_queue)->chunk_first->data) + ((_queue)->elem_size * (_queue)->chunk_first_index))) -#define CHUNK_LAST_ELEM(_queue) \ - ((void)0, \ - (((char *)(_queue)->chunk_last->data) + ((_queue)->elem_size * (_queue)->chunk_last_index))) - struct QueueChunk { struct QueueChunk *next; char data[0]; @@ -58,6 +50,16 @@ struct _GSQueue { size_t totelem; /* total number of elements */ }; +static void *queue_get_first_elem(GSQueue *queue) +{ + return ((char *)(queue)->chunk_first->data) + ((queue)->elem_size * (queue)->chunk_first_index); +} + +static void *queue_get_last_elem(GSQueue *queue) +{ + return ((char *)(queue)->chunk_last->data) + ((queue)->elem_size * (queue)->chunk_last_index); +} + /** * \return number of elements per chunk, optimized for slop-space. */ @@ -148,8 +150,7 @@ void BLI_gsqueue_push(GSQueue *queue, const void *src) BLI_assert(queue->chunk_last_index < queue->chunk_elem_max); /* Return last of queue */ - void *dst = CHUNK_LAST_ELEM(queue); - memcpy(dst, src, queue->elem_size); + memcpy(queue_get_last_elem(queue), src, queue->elem_size); } /** @@ -162,7 +163,7 @@ void BLI_gsqueue_pop(GSQueue *queue, void *dst) { BLI_assert(BLI_gsqueue_is_empty(queue) == false); - memcpy(dst, CHUNK_FIRST_ELEM(queue), queue->elem_size); + memcpy(dst, queue_get_first_elem(queue), queue->elem_size); queue->chunk_first_index++; queue->totelem--; diff --git a/source/blender/blenlib/intern/stack.c b/source/blender/blenlib/intern/stack.c index 76aef3761ae..301675c026e 100644 --- a/source/blender/blenlib/intern/stack.c +++ b/source/blender/blenlib/intern/stack.c @@ -36,10 +36,6 @@ /* ensure we get at least this many elems per chunk */ #define CHUNK_ELEM_MIN 32 -/* Gets the last element in the stack */ -#define CHUNK_LAST_ELEM(_stack) \ - ((void)0, (((char *)(_stack)->chunk_curr->data) + ((_stack)->elem_size * (_stack)->chunk_index))) - struct StackChunk { struct StackChunk *next; char data[0]; @@ -56,6 +52,11 @@ struct BLI_Stack { #endif }; +static void *stack_get_last_elem(BLI_Stack *stack) +{ + return ((char *)(stack)->chunk_curr->data) + ((stack)->elem_size * (stack)->chunk_index); +} + /** * \return number of elements per chunk, optimized for slop-space. */ @@ -148,7 +149,7 @@ void *BLI_stack_push_r(BLI_Stack *stack) #endif /* Return end of stack */ - return CHUNK_LAST_ELEM(stack); + return stack_get_last_elem(stack); } /** @@ -175,7 +176,7 @@ 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); + memcpy(dst, stack_get_last_elem(stack), stack->elem_size); BLI_stack_discard(stack); } @@ -220,7 +221,7 @@ void *BLI_stack_peek(BLI_Stack *stack) { BLI_assert(BLI_stack_is_empty(stack) == false); - return CHUNK_LAST_ELEM(stack); + return stack_get_last_elem(stack); } /** |