[Bf-blender-cvs] [bdd142bc022] master: Cleanup: convert some macros to functions

Brecht Van Lommel noreply at git.blender.org
Tue Oct 1 16:39:39 CEST 2019


Commit: bdd142bc022b131db7435a9d01ceaf1fdb1d8f24
Author: Brecht Van Lommel
Date:   Tue Oct 1 16:35:17 2019 +0200
Branches: master
https://developer.blender.org/rBbdd142bc022b131db7435a9d01ceaf1fdb1d8f24

Cleanup: convert some macros to functions

===================================================================

M	source/blender/blenlib/intern/gsqueue.c
M	source/blender/blenlib/intern/stack.c

===================================================================

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



More information about the Bf-blender-cvs mailing list