diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-09 14:41:05 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-09 14:41:05 +0400 |
commit | 1e784c54cd78d75a6eb94eccf81161265e297321 (patch) | |
tree | edd70cb4f722ced8c4474c10f74baa14321477de | |
parent | efcfe88adccbc1ce76407887aef61dab349d7eb2 (diff) |
bmesh speedup: skip free-realloc while running CustomData_bmesh_merge() when nothing is changed (happens quite often that there is nothing to do).
-rw-r--r-- | source/blender/blenkernel/BKE_customdata.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 30 |
2 files changed, 30 insertions, 5 deletions
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index bc94ab8ed41..b72667b5935 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -115,13 +115,13 @@ void CustomData_update_typemap(struct CustomData *data); /* 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 @@ bool CustomData_has_layer(const struct CustomData *data, int type); /* 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 */ diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 0988af87589..879d1895513 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -1257,13 +1257,14 @@ static int customdata_typemap_is_valid(const CustomData *data) } #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 @@ void CustomData_merge(const struct CustomData *source, struct CustomData *dest, 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 @@ int CustomData_number_of_layers(const CustomData *data, int type) 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_init_pool(CustomData *data, int totelem, const char htype) } } -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 @@ void CustomData_bmesh_merge(CustomData *source, CustomData *dest, 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 @@ void CustomData_bmesh_merge(CustomData *source, CustomData *dest, 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 @@ void CustomData_bmesh_merge(CustomData *source, CustomData *dest, totelem = bm->totvert; } - CustomData_merge(source, dest, mask, alloctype, 0); dest->pool = NULL; CustomData_bmesh_init_pool(dest, totelem, htype); @@ -2395,6 +2418,7 @@ void CustomData_bmesh_merge(CustomData *source, CustomData *dest, 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) |