[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59997] trunk/blender/source/blender/ blenlib/BLI_linklist_stack.h: add BLI_SMALLSTACK_***, macros: stack doesn' t have a fixed size, it uses stack memory and never allocates.

Campbell Barton ideasman42 at gmail.com
Tue Sep 10 13:04:20 CEST 2013


Revision: 59997
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59997
Author:   campbellbarton
Date:     2013-09-10 11:04:20 +0000 (Tue, 10 Sep 2013)
Log Message:
-----------
add BLI_SMALLSTACK_***, macros: stack doesn't have a fixed size, it uses stack memory and never allocates.
it can be added and removed many times per function but will always remain the size of the maximum number of items.

not used yet, added for normal calculation function from mont29.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_linklist_stack.h

Modified: trunk/blender/source/blender/blenlib/BLI_linklist_stack.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_linklist_stack.h	2013-09-10 10:57:49 UTC (rev 59996)
+++ trunk/blender/source/blender/blenlib/BLI_linklist_stack.h	2013-09-10 11:04:20 UTC (rev 59997)
@@ -40,6 +40,15 @@
  * \note _##var##_type is a dummy var only used for typechecks.
  */
 
+/* -------------------------------------------------------------------- */
+/* Linked Stack using BLI_mempool
+ *
+ * Uses mempool for storage.
+ */
+
+/** \name Linked Stack (mempool)
+ * \{ */
+
 #define BLI_LINKSTACK_DECLARE(var, type) \
 	LinkNode *var; \
 	BLI_mempool *_##var##_pool; \
@@ -87,4 +96,64 @@
 #include "BLI_linklist.h"
 #include "BLI_mempool.h"
 
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/* Linked Stack, using stack memory (alloca)
+ *
+ * alloca never frees, pop'd items are stored in a free-list for reuse.
+ * only use for lists small enough to fit on the stack.
+ */
+
+
+/** \name Linked Stack (alloca)
+ * \{ */
+
+#ifdef __GNUC__
+#  define _BLI_SMALLSTACK_CAST(var) typeof(_##var##_type)
+#else
+#  define _BLI_SMALLSTACK_CAST(var)
+#endif
+
+#define BLI_SMALLSTACK_DECLARE(var, type) \
+	LinkNode *_##var##_stack = NULL, *_##var##_free = NULL, *_##var##_temp = NULL; \
+	type _##var##_type
+
+#define BLI_SMALLSTACK_PUSH(var, data) \
+{ \
+	CHECK_TYPE_PAIR(data, _##var##_type); \
+	if (_##var##_free) { \
+		_##var##_temp = _##var##_free; \
+		_##var##_free = _##var##_free->next; \
+	} \
+	else { \
+		_##var##_temp = alloca(sizeof(LinkNode)); \
+	} \
+	_##var##_temp->next = _##var##_stack; \
+	_##var##_temp->link = data; \
+	_##var##_stack = _##var##_temp; \
+} (void)0
+
+/* internal use, no null check */
+#define _BLI_SMALLSTACK_DEL(var) \
+	(void)((_##var##_temp = _##var##_stack->next), \
+	       (_##var##_stack->next = _##var##_free), \
+	       (_##var##_free = _##var##_stack), \
+	       (_##var##_stack = _##var##_temp)) \
+
+/* check for typeof() */
+#define BLI_SMALLSTACK_POP(var) \
+	(_BLI_SMALLSTACK_CAST(var)) ((_##var##_stack) ? \
+	(_BLI_SMALLSTACK_DEL(var), (_##var##_free->link)) : NULL)
+
+#define BLI_SMALLSTACK_FREE(var)  { \
+	(void)&(_##var##_type); \
+} (void)0
+
+#include "BLI_alloca.h"
+
+/** \} */
+
 #endif  /* __BLI_LINKLIST_STACK_H__ */
+




More information about the Bf-blender-cvs mailing list