[Bf-blender-cvs] [1dbcccf] master: BLI_stack, add clear function.

Campbell Barton noreply at git.blender.org
Wed Jun 3 10:12:09 CEST 2015


Commit: 1dbcccf5f965187532a7fc543ca85bdbf79e99f5
Author: Campbell Barton
Date:   Wed Jun 3 18:06:47 2015 +1000
Branches: master
https://developer.blender.org/rB1dbcccf5f965187532a7fc543ca85bdbf79e99f5

BLI_stack, add clear function.

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

M	source/blender/blenlib/BLI_stack.h
M	source/blender/blenlib/intern/stack.c

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

diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h
index a8c4478..6d41e5f 100644
--- a/source/blender/blenlib/BLI_stack.h
+++ b/source/blender/blenlib/BLI_stack.h
@@ -48,6 +48,7 @@ void BLI_stack_pop(BLI_Stack *stack, void *dst) ATTR_NONNULL();
 
 void *BLI_stack_peek(BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 void  BLI_stack_discard(BLI_Stack *stack) ATTR_NONNULL();
+void  BLI_stack_clear(BLI_Stack *stack) ATTR_NONNULL();
 
 size_t BLI_stack_count(const BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 
diff --git a/source/blender/blenlib/intern/stack.c b/source/blender/blenlib/intern/stack.c
index 2d3a2f7..3c9e1a5 100644
--- a/source/blender/blenlib/intern/stack.c
+++ b/source/blender/blenlib/intern/stack.c
@@ -216,6 +216,41 @@ void BLI_stack_discard(BLI_Stack *stack)
 	}
 }
 
+/**
+ * Discards all elements without freeing.
+ */
+void BLI_stack_clear(BLI_Stack *stack)
+{
+#ifdef USE_TOTELEM
+	if (UNLIKELY(stack->totelem == 0)) {
+		return;
+	}
+	stack->totelem = 0;
+#else
+	if (UNLIKELY(stack->chunk_curr == NULL)) {
+		return;
+	}
+#endif
+
+	stack->chunk_index = stack->chunk_elem_max - 1;
+
+	if (stack->chunk_free) {
+		if (stack->chunk_curr) {
+			/* move all used chunks into tail of free list */
+			struct StackChunk *chunk_free_last = stack->chunk_free;
+			while (chunk_free_last->next) {
+				chunk_free_last = chunk_free_last->next;
+			}
+			chunk_free_last->next = stack->chunk_curr;
+			stack->chunk_curr = NULL;
+		}
+	}
+	else {
+		stack->chunk_free = stack->chunk_curr;
+		stack->chunk_curr = NULL;
+	}
+}
+
 size_t BLI_stack_count(const BLI_Stack *stack)
 {
 #ifdef USE_TOTELEM




More information about the Bf-blender-cvs mailing list