[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52134] trunk/blender/source/blender: BM_iter_as_arrayN() can now take an optional existing array argument, useful to avoid many small malloc' s by passing a fixes size stack variable instead.

Campbell Barton ideasman42 at gmail.com
Mon Nov 12 06:53:48 CET 2012


Revision: 52134
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52134
Author:   campbellbarton
Date:     2012-11-12 05:53:43 +0000 (Mon, 12 Nov 2012)
Log Message:
-----------
BM_iter_as_arrayN() can now take an optional existing array argument, useful to avoid many small malloc's by passing a fixes size stack variable instead.

Will give some speedup to edge-split modifier and bevel.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/mesh.c
    trunk/blender/source/blender/bmesh/bmesh_class.h
    trunk/blender/source/blender/bmesh/intern/bmesh_construct.c
    trunk/blender/source/blender/bmesh/intern/bmesh_core.c
    trunk/blender/source/blender/bmesh/intern/bmesh_decimate_dissolve.c
    trunk/blender/source/blender/bmesh/intern/bmesh_interp.c
    trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c
    trunk/blender/source/blender/bmesh/intern/bmesh_iterators.h
    trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
    trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
    trunk/blender/source/blender/bmesh/operators/bmo_bevel.c
    trunk/blender/source/blender/bmesh/operators/bmo_create.c
    trunk/blender/source/blender/bmesh/operators/bmo_extrude.c
    trunk/blender/source/blender/editors/mesh/editmesh_knife.c
    trunk/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c	2012-11-12 05:29:54 UTC (rev 52133)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c	2012-11-12 05:53:43 UTC (rev 52134)
@@ -3011,7 +3011,7 @@
 		MLoop *l_iter = loopstart;
 		float area, polynorm_local[3], (*vertexcos)[3];
 		const float *no = polynormal ? polynormal : polynorm_local;
-		BLI_array_fixedstack_declare(vertexcos, BM_NGON_STACK_SIZE, mpoly->totloop, __func__);
+		BLI_array_fixedstack_declare(vertexcos, BM_DEFAULT_NGON_STACK_SIZE, mpoly->totloop, __func__);
 
 		/* pack vertex cos into an array for area_poly_v3 */
 		for (i = 0; i < mpoly->totloop; i++, l_iter++) {

Modified: trunk/blender/source/blender/bmesh/bmesh_class.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh_class.h	2012-11-12 05:29:54 UTC (rev 52133)
+++ trunk/blender/source/blender/bmesh/bmesh_class.h	2012-11-12 05:53:43 UTC (rev 52134)
@@ -243,10 +243,16 @@
 #  define BM_FACE_FIRST_LOOP(p) ((p)->l_first)
 #endif
 
-/* size to use for static arrays when dealing with NGons,
+/**
+ * size to use for stack arrays when dealing with NGons,
  * alloc after this limit is reached.
  * this value is rather arbitrary */
-#define BM_NGON_STACK_SIZE 32
+#define BM_DEFAULT_NGON_STACK_SIZE 32
+/**
+ * size to use for stack arrays dealing with connected mesh data
+ * verts of faces, edges of vert - etc.
+ * often used with #BM_iter_as_arrayN() */
+#define BM_DEFAULT_ITER_STACK_SIZE 16
 
 /* avoid inf loop, this value is arbitrary
  * but should not error on valid cases */

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_construct.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_construct.c	2012-11-12 05:29:54 UTC (rev 52133)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_construct.c	2012-11-12 05:53:43 UTC (rev 52134)
@@ -174,9 +174,9 @@
 BMFace *BM_face_create_ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, int len, int nodouble)
 {
 	BMEdge **edges2 = NULL;
-	BLI_array_staticdeclare(edges2, BM_NGON_STACK_SIZE);
+	BLI_array_staticdeclare(edges2, BM_DEFAULT_NGON_STACK_SIZE);
 	BMVert **verts = NULL;
-	BLI_array_staticdeclare(verts, BM_NGON_STACK_SIZE);
+	BLI_array_staticdeclare(verts, BM_DEFAULT_NGON_STACK_SIZE);
 	BMFace *f = NULL;
 	BMEdge *e;
 	BMVert *v, *ev1, *ev2;

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_core.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_core.c	2012-11-12 05:29:54 UTC (rev 52133)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_core.c	2012-11-12 05:53:43 UTC (rev 52134)
@@ -195,8 +195,8 @@
 {
 	BMVert **verts = NULL;
 	BMEdge **edges = NULL;
-	BLI_array_fixedstack_declare(verts, BM_NGON_STACK_SIZE, f->len, __func__);
-	BLI_array_fixedstack_declare(edges, BM_NGON_STACK_SIZE, f->len, __func__);
+	BLI_array_fixedstack_declare(verts, BM_DEFAULT_NGON_STACK_SIZE, f->len, __func__);
+	BLI_array_fixedstack_declare(edges, BM_DEFAULT_NGON_STACK_SIZE, f->len, __func__);
 	BMLoop *l_iter;
 	BMLoop *l_first;
 	BMLoop *l_copy;
@@ -558,7 +558,7 @@
 void BM_face_edges_kill(BMesh *bm, BMFace *f)
 {
 	BMEdge **edges = NULL;
-	BLI_array_staticdeclare(edges, BM_NGON_STACK_SIZE);
+	BLI_array_staticdeclare(edges, BM_DEFAULT_NGON_STACK_SIZE);
 	BMLoop *l_iter;
 	BMLoop *l_first;
 	int i;
@@ -582,7 +582,7 @@
 void BM_face_verts_kill(BMesh *bm, BMFace *f)
 {
 	BMVert **verts = NULL;
-	BLI_array_staticdeclare(verts, BM_NGON_STACK_SIZE);
+	BLI_array_staticdeclare(verts, BM_DEFAULT_NGON_STACK_SIZE);
 	BMLoop *l_iter;
 	BMLoop *l_first;
 	int i;
@@ -734,7 +734,7 @@
 	const int do_disps = CustomData_has_layer(&bm->ldata, CD_MDISPS);
 	BMLoop *l_iter, *oldprev, *oldnext;
 	BMEdge **edar = NULL;
-	BLI_array_fixedstack_declare(edar, BM_NGON_STACK_SIZE, len, __func__);
+	BLI_array_fixedstack_declare(edar, BM_DEFAULT_NGON_STACK_SIZE, len, __func__);
 	int i, j, edok;
 
 	for (i = 0, l_iter = l_first; i < len; i++, l_iter = l_iter->next) {
@@ -937,9 +937,9 @@
 	BMEdge **edges = NULL;
 	BMEdge **deledges = NULL;
 	BMVert **delverts = NULL;
-	BLI_array_staticdeclare(edges,    BM_NGON_STACK_SIZE);
-	BLI_array_staticdeclare(deledges, BM_NGON_STACK_SIZE);
-	BLI_array_staticdeclare(delverts, BM_NGON_STACK_SIZE);
+	BLI_array_staticdeclare(edges,    BM_DEFAULT_NGON_STACK_SIZE);
+	BLI_array_staticdeclare(deledges, BM_DEFAULT_NGON_STACK_SIZE);
+	BLI_array_staticdeclare(delverts, BM_DEFAULT_NGON_STACK_SIZE);
 	BMVert *v1 = NULL, *v2 = NULL;
 	const char *err = NULL;
 	int i, tote = 0;
@@ -1587,7 +1587,7 @@
 
 				if (LIKELY(radlen)) {
 					BMLoop **loops = NULL;
-					BLI_array_fixedstack_declare(loops, BM_NGON_STACK_SIZE, radlen, __func__);
+					BLI_array_fixedstack_declare(loops, BM_DEFAULT_NGON_STACK_SIZE, radlen, __func__);
 
 					killoop = ke->l;
 
@@ -1808,23 +1808,28 @@
  */
 int BM_vert_splice(BMesh *bm, BMVert *v, BMVert *v_target)
 {
-	BMEdge *e;
-
+	void *loops_stack[BM_DEFAULT_ITER_STACK_SIZE];
 	BMLoop **loops;
 	int i, loops_tot;
 
+	BMEdge *e;
+
 	/* verts already spliced */
 	if (v == v_target) {
 		return FALSE;
 	}
 
 	/* we can't modify the vert while iterating so first allocate an array of loops */
-	loops = BM_iter_as_arrayN(bm, BM_LOOPS_OF_VERT, v, &loops_tot);
-	if (loops) {
+	loops = BM_iter_as_arrayN(bm, BM_LOOPS_OF_VERT, v, &loops_tot,
+	                          (void **)loops_stack, BM_DEFAULT_ITER_STACK_SIZE);
+
+	if (LIKELY(loops != NULL)) {
 		for (i = 0; i < loops_tot; i++) {
 			loops[i]->v = v_target;
 		}
-		MEM_freeN(loops);
+		if (loops != (BMLoop **)loops_stack) {
+			MEM_freeN(loops);
+		}
 	}
 
 	/* move all the edges from v's disk to vtarget's disk */

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_decimate_dissolve.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_decimate_dissolve.c	2012-11-12 05:29:54 UTC (rev 52133)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_decimate_dissolve.c	2012-11-12 05:53:43 UTC (rev 52134)
@@ -231,8 +231,8 @@
 	int vinput_len;
 	int einput_len;
 
-	BMVert **vinput_arr = BM_iter_as_arrayN(bm, BM_VERTS_OF_MESH, NULL, &vinput_len);
-	BMEdge **einput_arr = BM_iter_as_arrayN(bm, BM_EDGES_OF_MESH, NULL, &einput_len);
+	BMVert **vinput_arr = BM_iter_as_arrayN(bm, BM_VERTS_OF_MESH, NULL, &vinput_len, NULL, 0);
+	BMEdge **einput_arr = BM_iter_as_arrayN(bm, BM_EDGES_OF_MESH, NULL, &einput_len, NULL, 0);
 
 	BM_mesh_decimate_dissolve_ex(bm, angle_limit, do_dissolve_boundaries,
 	                             vinput_arr, vinput_len,

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_interp.c	2012-11-12 05:29:54 UTC (rev 52133)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_interp.c	2012-11-12 05:53:43 UTC (rev 52134)
@@ -174,9 +174,9 @@
 
 	void **blocks = NULL;
 	float (*cos)[3] = NULL, *w = NULL;
-	BLI_array_fixedstack_declare(cos,     BM_NGON_STACK_SIZE, source->len, __func__);
-	BLI_array_fixedstack_declare(w,       BM_NGON_STACK_SIZE, source->len, __func__);
-	BLI_array_fixedstack_declare(blocks,  BM_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(cos,     BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(w,       BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(blocks,  BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
 	int i;
 	
 	BM_elem_attrs_copy(bm, bm, source, target);
@@ -613,10 +613,10 @@
 	void **vblocks = NULL;
 	float (*cos)[3] = NULL, co[3], *w = NULL;
 	float cent[3] = {0.0f, 0.0f, 0.0f};
-	BLI_array_fixedstack_declare(cos,      BM_NGON_STACK_SIZE, source->len, __func__);
-	BLI_array_fixedstack_declare(w,        BM_NGON_STACK_SIZE, source->len, __func__);
-	BLI_array_fixedstack_declare(blocks,   BM_NGON_STACK_SIZE, source->len, __func__);
-	BLI_array_fixedstack_declare(vblocks,  BM_NGON_STACK_SIZE, do_vertex ? source->len : 0, __func__);
+	BLI_array_fixedstack_declare(cos,      BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(w,        BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(blocks,   BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(vblocks,  BM_DEFAULT_NGON_STACK_SIZE, do_vertex ? source->len : 0, __func__);
 	int i, ax, ay;
 
 	BM_elem_attrs_copy(bm, bm, source, target->f);
@@ -689,9 +689,9 @@
 	void **blocks = NULL;
 	float (*cos)[3] = NULL, *w = NULL;
 	float cent[3] = {0.0f, 0.0f, 0.0f};
-	BLI_array_fixedstack_declare(cos,      BM_NGON_STACK_SIZE, source->len, __func__);
-	BLI_array_fixedstack_declare(w,        BM_NGON_STACK_SIZE, source->len, __func__);
-	BLI_array_fixedstack_declare(blocks,   BM_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(cos,      BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(w,        BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+	BLI_array_fixedstack_declare(blocks,   BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
 	int i;
 
 	i = 0;

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c	2012-11-12 05:29:54 UTC (rev 52133)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c	2012-11-12 05:53:43 UTC (rev 52134)
@@ -116,10 +116,14 @@
  *
  * Caller needs to free the array.
  */
-void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len)
+void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len,
+                        /* optional static vars to avoid an alloc */
+                        void **stack_array, int stack_array_size)
 {
 	BMIter iter;
 
+	BLI_assert(stack_array_size == 0 || (stack_array_size && stack_array));
+
 	/* we can't rely on coun't being set */
 	switch (itype) {
 		case BM_VERTS_OF_MESH:
@@ -137,7 +141,9 @@
 
 	if (BM_iter_init(&iter, bm, itype, data) && iter.count > 0) {
 		BMElem *ele;
-		BMElem **array = MEM_mallocN(sizeof(ele) * iter.count, __func__);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list