[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50432] trunk/blender/source/blender/bmesh /operators/bmo_subdivide.c: code cleanup: bmesh subdivide code was growing arrays one by one, when the final size is known - do this in one go.

Campbell Barton ideasman42 at gmail.com
Wed Sep 5 21:21:55 CEST 2012


Revision: 50432
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50432
Author:   campbellbarton
Date:     2012-09-05 19:21:55 +0000 (Wed, 05 Sep 2012)
Log Message:
-----------
code cleanup: bmesh subdivide code was growing arrays one by one, when the final size is known - do this in one go.
also replace for loops with iterator macros.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c

Modified: trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c	2012-09-05 18:35:22 UTC (rev 50431)
+++ trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c	2012-09-05 19:21:55 UTC (rev 50432)
@@ -938,9 +938,9 @@
 			BLI_array_empty(splits);
 
 			/* for case of two edges, connecting them shouldn't be too hard */
-			BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) {
-				BLI_array_grow_one(loops);
-				loops[BLI_array_count(loops) - 1] = l;
+			BLI_array_grow_items(loops, face->len);
+			BM_ITER_ELEM_INDEX (l, &liter, face, BM_LOOPS_OF_FACE, a) {
+				loops[a] = l;
 			}
 			
 			vlen = BLI_array_count(loops);
@@ -971,18 +971,21 @@
 			
 			b += numcuts - 1;
 
+			BLI_array_grow_items(splits, numcuts * 2);
 			for (j = 0; j < numcuts; j++) {
-				BLI_array_grow_one(splits);
-				splits[BLI_array_count(splits) - 1] = loops[a];
-				
-				BLI_array_grow_one(splits);
-				splits[BLI_array_count(splits) - 1] = loops[b];
+				splits[j * 2 + 0] = loops[a];
+				splits[j * 2 + 1] = loops[b];
 
 				b = (b - 1) % vlen;
 				a = (a + 1) % vlen;
 			}
 			
-			//BM_face_legal_splits(bmesh, face, splits, BLI_array_count(splits) / 2);
+			/* Since these are newly created vertices, we don't need to worry about them being legal,
+			 * ... though there are some cases we _should_ check for
+			 * - concave corner of an ngon.
+			 * - 2 edges being used in 2+ ngons.
+			 */
+			// BM_face_legal_splits(bm, face, (BMLoop *(*)[2])splits, BLI_array_count(splits) / 2);
 
 			for (j = 0; j < BLI_array_count(splits) / 2; j++) {
 				if (splits[j * 2]) {
@@ -997,27 +1000,19 @@
 			continue;
 		}
 
-		j = a = 0;
-		for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face);
-		     nl;
-		     nl = BM_iter_step(&liter))
-		{
+		a = 0;
+		BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) {
 			if (nl->v == facedata[i].start) {
 				a = j + 1;
 				break;
 			}
-			j++;
 		}
 
-		for (j = 0; j < face->len; j++) {
-			BLI_array_grow_one(verts);
-		}
-		
-		j = 0;
-		for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face); nl; nl = BM_iter_step(&liter)) {
+		BLI_array_grow_items(verts, face->len);
+
+		BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) {
 			b = (j - a + face->len) % face->len;
 			verts[b] = nl->v;
-			j += 1;
 		}
 
 		BM_CHECK_ELEMENT(face);




More information about the Bf-blender-cvs mailing list