Cleanup: convert some macros to functions

This commit is contained in:
Brecht Van Lommel 2019-10-01 16:35:17 +02:00
parent 2bddf44b11
commit bdd142bc02
2 changed files with 20 additions and 18 deletions

View File

@ -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--;

View File

@ -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);
}
/**