Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-09-11 10:12:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-09-11 10:12:48 +0400
commit39231c90dd5b986612cffd00fe65760430e04c83 (patch)
treea8e024a9a1f1fa7624180c03e9425c37f47aaac7 /source/blender/bmesh/intern/bmesh_iterators.c
parent2f436612fe0e4e2986452c3b9d0249b8fd340f8b (diff)
fix [#31738] BM_vert_splice modifies loops during iteration
patch by Nicholas Bishop, modified to avoid looping over vert-loops one extra time. added BM_iter_as_arrayN(), returns an iterator as an array without knowing the length before calling.
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_iterators.c')
-rw-r--r--source/blender/bmesh/intern/bmesh_iterators.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_iterators.c b/source/blender/bmesh/intern/bmesh_iterators.c
index 8103ae1ee11..64920df6e20 100644
--- a/source/blender/bmesh/intern/bmesh_iterators.c
+++ b/source/blender/bmesh/intern/bmesh_iterators.c
@@ -28,6 +28,8 @@
* See: bmesh_iterators_inlin.c too, some functions are here for speed reasons.
*/
+#include "MEM_guardedalloc.h"
+
#include "BLI_utildefines.h"
#include "bmesh.h"
@@ -105,6 +107,38 @@ int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, cons
}
/**
+ * \brief Iterator as Array
+ *
+ * Allocates a new array, has the advantage that you dont need to know the size ahead of time.
+ *
+ * Takes advantage of less common iterator usage to avoid counting twice,
+ * which you might end up doing when #BM_iter_as_array is used.
+ *
+ * Caller needs to free the array.
+ */
+void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len)
+{
+ BMIter iter;
+
+ if (BM_iter_init(&iter, bm, itype, data) && iter.count > 0) {
+ BMElem *ele;
+ BMElem **array = MEM_mallocN(sizeof(ele) * iter.count, __func__);
+ int i;
+
+ *r_len = iter.count; /* set before iterating */
+
+ for (ele = BM_iter_step(&iter), i = 0; ele; ele = BM_iter_step(&iter), i++) {
+ array[i] = ele;
+ }
+ return array;
+ }
+ else {
+ *r_len = 0;
+ return NULL;
+ }
+}
+
+/**
* \brief Elem Iter Flag Count
*
* Counts how many flagged / unflagged items are found in this element.