speedup for freeing bmeshes, skip calling free on every
vert/edge/face/loop if there are no free functions for the customdata layers.
This commit is contained in:
@@ -88,6 +88,7 @@ bool CustomData_layer_has_interp(struct CustomData *data, int layer_n);
|
||||
*/
|
||||
bool CustomData_has_math(struct CustomData *data);
|
||||
bool CustomData_has_interp(struct CustomData *data);
|
||||
bool CustomData_bmesh_has_free(struct CustomData *data);
|
||||
|
||||
/* copies the "value" (e.g. mloopuv uv or mloopcol colors) from one block to
|
||||
* another, while not overwriting anything else (e.g. flags). probably only
|
||||
|
||||
@@ -2552,6 +2552,23 @@ bool CustomData_has_math(struct CustomData *data)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* a non bmesh version would have to check layer->data */
|
||||
bool CustomData_bmesh_has_free(struct CustomData *data)
|
||||
{
|
||||
const LayerTypeInfo *typeInfo;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < data->totlayer; ++i) {
|
||||
if (!(data->layers[i].flag & CD_FLAG_NOFREE)) {
|
||||
typeInfo = layerType_getInfo(data->layers[i].type);
|
||||
if (typeInfo->free) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CustomData_has_interp(struct CustomData *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -164,21 +164,37 @@ void BM_mesh_data_free(BMesh *bm)
|
||||
BMEdge *e;
|
||||
BMLoop *l;
|
||||
BMFace *f;
|
||||
|
||||
|
||||
BMIter iter;
|
||||
BMIter itersub;
|
||||
|
||||
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
|
||||
CustomData_bmesh_free_block(&(bm->vdata), &(v->head.data));
|
||||
|
||||
bool is_ldata_free;
|
||||
bool is_pdata_free;
|
||||
|
||||
|
||||
/* Check if we have to call free, if not we can avoid a lot of looping */
|
||||
if (CustomData_bmesh_has_free(&(bm->vdata))) {
|
||||
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
|
||||
CustomData_bmesh_free_block(&(bm->vdata), &(v->head.data));
|
||||
}
|
||||
}
|
||||
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
||||
CustomData_bmesh_free_block(&(bm->edata), &(e->head.data));
|
||||
if (CustomData_bmesh_has_free(&(bm->edata))) {
|
||||
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
||||
CustomData_bmesh_free_block(&(bm->edata), &(e->head.data));
|
||||
}
|
||||
}
|
||||
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
||||
CustomData_bmesh_free_block(&(bm->pdata), &(f->head.data));
|
||||
BM_ITER_ELEM (l, &itersub, f, BM_LOOPS_OF_FACE) {
|
||||
CustomData_bmesh_free_block(&(bm->ldata), &(l->head.data));
|
||||
|
||||
if ((is_ldata_free = CustomData_bmesh_has_free(&(bm->ldata))) ||
|
||||
(is_pdata_free = CustomData_bmesh_has_free(&(bm->pdata))))
|
||||
{
|
||||
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
||||
if (is_pdata_free)
|
||||
CustomData_bmesh_free_block(&(bm->pdata), &(f->head.data));
|
||||
if (is_ldata_free) {
|
||||
BM_ITER_ELEM (l, &itersub, f, BM_LOOPS_OF_FACE) {
|
||||
CustomData_bmesh_free_block(&(bm->ldata), &(l->head.data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user