[Bf-blender-cvs] [0cf8ee1] master: BMesh: use stack for subdiv face data (no realloc)

Campbell Barton noreply at git.blender.org
Sun Sep 28 07:09:18 CEST 2014


Commit: 0cf8ee1c03301d5fae329a4640f20fbf788cd468
Author: Campbell Barton
Date:   Sun Sep 28 13:27:47 2014 +1000
Branches: master
https://developer.blender.org/rB0cf8ee1c03301d5fae329a4640f20fbf788cd468

BMesh: use stack for subdiv face data (no realloc)

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

M	source/blender/bmesh/operators/bmo_subdivide.c

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

diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c
index fc507cd..0d9ce4b 100644
--- a/source/blender/bmesh/operators/bmo_subdivide.c
+++ b/source/blender/bmesh/operators/bmo_subdivide.c
@@ -32,6 +32,7 @@
 #include "BLI_rand.h"
 #include "BLI_array.h"
 #include "BLI_noise.h"
+#include "BLI_stack.h"
 
 #include "BKE_customdata.h"
 
@@ -766,8 +767,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 	BMOpSlot *einput;
 	const SubDPattern *pat;
 	SubDParams params;
-	SubDFaceData *facedata = NULL;
-	BLI_array_declare(facedata);
+	BLI_Stack *facedata;
 	BMIter viter, fiter, liter;
 	BMVert *v, **verts = NULL;
 	BMEdge *edge;
@@ -782,7 +782,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 	BLI_array_declare(verts);
 	float smooth, fractal, along_normal;
 	bool use_sphere, use_single_edge, use_grid_fill, use_only_quads;
-	int cornertype, seed, i, j, matched, a, b, numcuts, totesel, smooth_falloff;
+	int cornertype, seed, i, j, a, b, numcuts, totesel, smooth_falloff;
 	
 	BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, SUBD_SPLIT);
 	
@@ -875,9 +875,12 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 	                     BM_EDGE, EDGE_PERCENT);
 
 
+	facedata = BLI_stack_new(sizeof(SubDFaceData), __func__);
+
 	BM_ITER_MESH (face, &fiter, bm, BM_FACES_OF_MESH) {
 		BMEdge *e1 = NULL, *e2 = NULL;
 		float vec1[3], vec2[3];
+		bool matched = false;
 
 		/* skip non-quads if requested */
 		if (use_only_quads && face->len != 4)
@@ -891,8 +894,6 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 		BLI_array_grow_items(edges, face->len);
 		BLI_array_grow_items(verts, face->len);
 
-		matched = 0;
-
 		totesel = 0;
 		BM_ITER_ELEM_INDEX (l_new, &liter, face, BM_LOOPS_OF_FACE, i) {
 			edges[i] = l_new->e;
@@ -930,12 +931,13 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 					}
 				}
 				if (matched) {
-					BLI_array_grow_one(facedata);
-					b = BLI_array_count(facedata) - 1;
-					facedata[b].pat = pat;
-					facedata[b].start = verts[i];
-					facedata[b].face = face;
-					facedata[b].totedgesel = totesel;
+					SubDFaceData *fd;
+
+					fd = BLI_stack_push_r(facedata);
+					fd->pat = pat;
+					fd->start = verts[i];
+					fd->face = face;
+					fd->totedgesel = totesel;
 					BMO_elem_flag_enable(bm, face, SUBD_SPLIT);
 					break;
 				}
@@ -966,15 +968,15 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 					}
 				}
 				if (matched) {
-					BLI_array_grow_one(facedata);
-					j = BLI_array_count(facedata) - 1;
+					SubDFaceData *fd;
 
 					BMO_elem_flag_enable(bm, face, SUBD_SPLIT);
 
-					facedata[j].pat = pat;
-					facedata[j].start = verts[a];
-					facedata[j].face = face;
-					facedata[j].totedgesel = totesel;
+					fd = BLI_stack_push_r(facedata);
+					fd->pat = pat;
+					fd->start = verts[a];
+					fd->face = face;
+					fd->totedgesel = totesel;
 					break;
 				}
 			}
@@ -982,16 +984,16 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 		}
 		
 		if (!matched && totesel) {
-			BLI_array_grow_one(facedata);
-			j = BLI_array_count(facedata) - 1;
+			SubDFaceData *fd;
 			
 			BMO_elem_flag_enable(bm, face, SUBD_SPLIT);
 
 			/* must initialize all members here */
-			facedata[j].start = NULL;
-			facedata[j].pat = NULL;
-			facedata[j].totedgesel = totesel;
-			facedata[j].face = face;
+			fd = BLI_stack_push_r(facedata);
+			fd->start = NULL;
+			fd->pat = NULL;
+			fd->totedgesel = totesel;
+			fd->face = face;
 		}
 	}
 
@@ -1009,16 +1011,17 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 		copy_v3_v3(v->co, co);
 	}
 
-	i = 0;
-	for (i = 0; i < BLI_array_count(facedata); i++) {
-		face = facedata[i].face;
+	for (; !BLI_stack_is_empty(facedata); BLI_stack_discard(facedata)) {
+		SubDFaceData *fd = BLI_stack_peek(facedata);
+
+		face = fd->face;
 
 		/* figure out which pattern to use */
 		BLI_array_empty(verts);
 
-		pat = facedata[i].pat;
+		pat = fd->pat;
 
-		if (!pat && facedata[i].totedgesel == 2) {
+		if (!pat && fd->totedgesel == 2) {
 			int vlen;
 			
 			/* ok, no pattern.  we still may be able to do something */
@@ -1131,7 +1134,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 
 		a = 0;
 		BM_ITER_ELEM_INDEX (l_new, &liter, face, BM_LOOPS_OF_FACE, j) {
-			if (l_new->v == facedata[i].start) {
+			if (l_new->v == fd->start) {
 				a = j + 1;
 				break;
 			}
@@ -1156,7 +1159,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
 
 	BM_data_layer_free_n(bm, &bm->vdata, CD_SHAPEKEY, params.shape_info.tmpkey);
 	
-	if (facedata) BLI_array_free(facedata);
+	BLI_stack_free(facedata);
 	if (edges) BLI_array_free(edges);
 	if (verts) BLI_array_free(verts);
 	BLI_array_free(loops_split);




More information about the Bf-blender-cvs mailing list