minor speedup for bmesh - add CustomData_bmesh_free_block_data(), use

when the block would be immediately allocated again.
This commit is contained in:
Campbell Barton
2013-05-08 13:00:25 +00:00
parent 8d0de0c3cf
commit 8ac2fee57a
4 changed files with 33 additions and 6 deletions

View File

@@ -307,6 +307,7 @@ void CustomData_set_layer_flag(struct CustomData *data, int type, int flag);
void CustomData_bmesh_set_default(struct CustomData *data, void **block);
void CustomData_bmesh_free_block(struct CustomData *data, void **block);
void CustomData_bmesh_free_block_data(struct CustomData *data, void **block);
/* copy custom data to/from layers as in mesh/derivedmesh, to editmesh
* blocks of data. the CustomData's must not be compatible */

View File

@@ -2422,6 +2422,32 @@ void CustomData_bmesh_free_block(CustomData *data, void **block)
*block = NULL;
}
/**
* Same as #CustomData_bmesh_free_block but zero the memory rather then freeing.
*/
void CustomData_bmesh_free_block_data(CustomData *data, void **block)
{
const LayerTypeInfo *typeInfo;
int i;
if (*block == NULL)
return;
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) {
int offset = data->layers[i].offset;
typeInfo->free((char *)*block + offset, 1, typeInfo->size);
}
}
}
if (data->totsize)
memset(*block, 0, data->totsize);
}
static void CustomData_bmesh_alloc_block(CustomData *data, void **block)
{

View File

@@ -759,7 +759,7 @@ static void bm_vert_attrs_copy(BMesh *source_mesh, BMesh *target_mesh,
return;
}
copy_v3_v3(target_vertex->no, source_vertex->no);
CustomData_bmesh_free_block(&target_mesh->vdata, &target_vertex->head.data);
CustomData_bmesh_free_block_data(&target_mesh->vdata, &target_vertex->head.data);
CustomData_bmesh_copy_data(&source_mesh->vdata, &target_mesh->vdata,
source_vertex->head.data, &target_vertex->head.data);
}
@@ -771,7 +771,7 @@ static void bm_edge_attrs_copy(BMesh *source_mesh, BMesh *target_mesh,
BLI_assert(!"BMEdge: source and targer match");
return;
}
CustomData_bmesh_free_block(&target_mesh->edata, &target_edge->head.data);
CustomData_bmesh_free_block_data(&target_mesh->edata, &target_edge->head.data);
CustomData_bmesh_copy_data(&source_mesh->edata, &target_mesh->edata,
source_edge->head.data, &target_edge->head.data);
}
@@ -783,7 +783,7 @@ static void bm_loop_attrs_copy(BMesh *source_mesh, BMesh *target_mesh,
BLI_assert(!"BMLoop: source and targer match");
return;
}
CustomData_bmesh_free_block(&target_mesh->ldata, &target_loop->head.data);
CustomData_bmesh_free_block_data(&target_mesh->ldata, &target_loop->head.data);
CustomData_bmesh_copy_data(&source_mesh->ldata, &target_mesh->ldata,
source_loop->head.data, &target_loop->head.data);
}
@@ -796,7 +796,7 @@ static void bm_face_attrs_copy(BMesh *source_mesh, BMesh *target_mesh,
return;
}
copy_v3_v3(target_face->no, source_face->no);
CustomData_bmesh_free_block(&target_mesh->pdata, &target_face->head.data);
CustomData_bmesh_free_block_data(&target_mesh->pdata, &target_face->head.data);
CustomData_bmesh_copy_data(&source_mesh->pdata, &target_mesh->pdata,
source_face->head.data, &target_face->head.data);
target_face->mat_nr = source_face->mat_nr;

View File

@@ -55,7 +55,7 @@ static void bm_data_interp_from_elem(CustomData *data_layer, BMElem *ele1, BMEle
/* do nothing */
}
else {
CustomData_bmesh_free_block(data_layer, &ele_dst->head.data);
CustomData_bmesh_free_block_data(data_layer, &ele_dst->head.data);
CustomData_bmesh_copy_data(data_layer, data_layer, ele1->head.data, &ele_dst->head.data);
}
}
@@ -64,7 +64,7 @@ static void bm_data_interp_from_elem(CustomData *data_layer, BMElem *ele1, BMEle
/* do nothing */
}
else {
CustomData_bmesh_free_block(data_layer, &ele_dst->head.data);
CustomData_bmesh_free_block_data(data_layer, &ele_dst->head.data);
CustomData_bmesh_copy_data(data_layer, data_layer, ele2->head.data, &ele_dst->head.data);
}
}