[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56614] trunk/blender/source/blender/ blenkernel: bmesh speedup: skip free-realloc while running CustomData_bmesh_merge() when nothing is changed (happens quite often that there is nothing to do).

Campbell Barton ideasman42 at gmail.com
Thu May 9 12:41:06 CEST 2013


Revision: 56614
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56614
Author:   campbellbarton
Date:     2013-05-09 10:41:05 +0000 (Thu, 09 May 2013)
Log Message:
-----------
bmesh speedup: skip free-realloc while running CustomData_bmesh_merge() when nothing is changed (happens quite often that there is nothing to do).

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

Modified: trunk/blender/source/blender/blenkernel/BKE_customdata.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_customdata.h	2013-05-09 10:13:13 UTC (rev 56613)
+++ trunk/blender/source/blender/blenkernel/BKE_customdata.h	2013-05-09 10:41:05 UTC (rev 56614)
@@ -115,13 +115,13 @@
 
 /* same as the above, except that this will preserve existing layers, and only
  * add the layers that were not there yet */
-void CustomData_merge(const struct CustomData *source, struct CustomData *dest,
+bool CustomData_merge(const struct CustomData *source, struct CustomData *dest,
                       CustomDataMask mask, int alloctype, int totelem);
 
 /* bmesh version of CustomData_merge; merges the layouts of source and dest,
  * then goes through the mesh and makes sure all the customdata blocks are
  * consistent with the new layout.*/
-void CustomData_bmesh_merge(struct CustomData *source, struct CustomData *dest, 
+bool CustomData_bmesh_merge(struct CustomData *source, struct CustomData *dest,
                             CustomDataMask mask, int alloctype, struct BMesh *bm, const char htype);
 
 /** NULL's all members and resets the typemap. */
@@ -167,6 +167,7 @@
 
 /* returns the number of layers with this type */
 int CustomData_number_of_layers(const struct CustomData *data, int type);
+int CustomData_number_of_layers_typemask(const struct CustomData *data, CustomDataMask mask);
 
 /* duplicate data of a layer with flag NOFREE, and remove that flag.
  * returns the layer data */

Modified: trunk/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata.c	2013-05-09 10:13:13 UTC (rev 56613)
+++ trunk/blender/source/blender/blenkernel/intern/customdata.c	2013-05-09 10:41:05 UTC (rev 56614)
@@ -1257,13 +1257,14 @@
 }
 #endif
 
-void CustomData_merge(const struct CustomData *source, struct CustomData *dest,
+bool CustomData_merge(const struct CustomData *source, struct CustomData *dest,
                       CustomDataMask mask, int alloctype, int totelem)
 {
 	/*const LayerTypeInfo *typeInfo;*/
 	CustomDataLayer *layer, *newlayer;
 	void *data;
 	int i, type, number = 0, lasttype = -1, lastactive = 0, lastrender = 0, lastclone = 0, lastmask = 0, lastflag = 0;
+	bool change = false;
 
 	for (i = 0; i < source->totlayer; ++i) {
 		layer = &source->layers[i];
@@ -1313,10 +1314,12 @@
 			newlayer->active_clone = lastclone;
 			newlayer->active_mask = lastmask;
 			newlayer->flag |= lastflag & (CD_FLAG_EXTERNAL | CD_FLAG_IN_MEMORY);
+			change = true;
 		}
 	}
 
 	CustomData_update_typemap(dest);
+	return change;
 }
 
 void CustomData_copy(const struct CustomData *source, struct CustomData *dest,
@@ -1779,6 +1782,17 @@
 	return number;
 }
 
+int CustomData_number_of_layers_typemask(const CustomData *data, CustomDataMask mask)
+{
+	int i, number = 0;
+
+	for (i = 0; i < data->totlayer; i++)
+		if (mask & CD_TYPE_AS_MASK(data->layers[i].type))
+			number++;
+
+	return number;
+}
+
 void *CustomData_duplicate_referenced_layer(struct CustomData *data, const int type, const int totelem)
 {
 	CustomDataLayer *layer;
@@ -2324,7 +2338,7 @@
 	}
 }
 
-void CustomData_bmesh_merge(CustomData *source, CustomData *dest, 
+bool CustomData_bmesh_merge(CustomData *source, CustomData *dest,
                             CustomDataMask mask, int alloctype, BMesh *bm, const char htype)
 {
 	BMHeader *h;
@@ -2334,6 +2348,10 @@
 	int iter_type;
 	int totelem;
 
+	if (CustomData_number_of_layers_typemask(source, mask) == 0) {
+		return false;
+	}
+
 	/* copy old layer description so that old data can be copied into
 	 * the new allocation */
 	destold = *dest;
@@ -2341,6 +2359,12 @@
 		destold.layers = MEM_dupallocN(destold.layers);
 	}
 
+	if (CustomData_merge(source, dest, mask, alloctype, 0) == false) {
+		if (destold.layers)
+			MEM_freeN(destold.layers);
+		return false;
+	}
+
 	switch (htype) {
 		case BM_VERT:
 			iter_type = BM_VERTS_OF_MESH;
@@ -2364,7 +2388,6 @@
 			totelem = bm->totvert;
 	}
 
-	CustomData_merge(source, dest, mask, alloctype, 0);
 	dest->pool = NULL;
 	CustomData_bmesh_init_pool(dest, totelem, htype);
 
@@ -2395,6 +2418,7 @@
 
 	if (destold.pool) BLI_mempool_destroy(destold.pool);
 	if (destold.layers) MEM_freeN(destold.layers);
+	return true;
 }
 
 void CustomData_bmesh_free_block(CustomData *data, void **block)




More information about the Bf-blender-cvs mailing list