[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53635] trunk/blender/source/blender/ blenkernel/intern/customdata.c: minor improvement to CustomData_bmesh_merge (), allocate the correct size pool rather then always 512.

Campbell Barton ideasman42 at gmail.com
Mon Jan 7 16:35:22 CET 2013


Revision: 53635
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53635
Author:   campbellbarton
Date:     2013-01-07 15:35:20 +0000 (Mon, 07 Jan 2013)
Log Message:
-----------
minor improvement to CustomData_bmesh_merge(), allocate the correct size pool rather then always 512.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/customdata.c

Modified: trunk/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata.c	2013-01-07 15:29:15 UTC (rev 53634)
+++ trunk/blender/source/blender/blenkernel/intern/customdata.c	2013-01-07 15:35:20 UTC (rev 53635)
@@ -2298,34 +2298,45 @@
 	BMIter iter;
 	CustomData destold;
 	void *tmp;
-	int t;
+	int iter_type;
+	int totelem;
 
 	/* copy old layer description so that old data can be copied into
 	 * the new allocation */
 	destold = *dest;
-	if (destold.layers) destold.layers = MEM_dupallocN(destold.layers);
-	
-	CustomData_merge(source, dest, mask, alloctype, 0);
-	dest->pool = NULL;
-	CustomData_bmesh_init_pool(dest, 512, htype);
+	if (destold.layers) {
+		destold.layers = MEM_dupallocN(destold.layers);
+	}
 
 	switch (htype) {
 		case BM_VERT:
-			t = BM_VERTS_OF_MESH; break;
+			iter_type = BM_VERTS_OF_MESH;
+			totelem = bm->totvert;
+			break;
 		case BM_EDGE:
-			t = BM_EDGES_OF_MESH; break;
+			iter_type = BM_EDGES_OF_MESH;
+			totelem = bm->totedge;
+			break;
 		case BM_LOOP:
-			t = BM_LOOPS_OF_FACE; break;
+			iter_type = BM_LOOPS_OF_FACE;
+			totelem = bm->totloop;
+			break;
 		case BM_FACE:
-			t = BM_FACES_OF_MESH; break;
+			iter_type = BM_FACES_OF_MESH;
+			totelem = bm->totface;
+			break;
 		default: /* should never happen */
 			BLI_assert(!"invalid type given");
-			t = BM_VERTS_OF_MESH;
+			iter_type = BM_VERTS_OF_MESH;
 	}
 
-	if (t != BM_LOOPS_OF_FACE) {
+	CustomData_merge(source, dest, mask, alloctype, 0);
+	dest->pool = NULL;
+	CustomData_bmesh_init_pool(dest, totelem, htype);
+
+	if (iter_type != BM_LOOPS_OF_FACE) {
 		/*ensure all current elements follow new customdata layout*/
-		BM_ITER_MESH (h, &iter, bm, t) {
+		BM_ITER_MESH (h, &iter, bm, iter_type) {
 			tmp = NULL;
 			CustomData_bmesh_copy_data(&destold, dest, h->data, &tmp);
 			CustomData_bmesh_free_block(&destold, &h->data);




More information about the Bf-blender-cvs mailing list