[Bf-blender-cvs] [9c12ca2] mesh-transfer-data: Mesh loop-island api: reuse the memory arena
Campbell Barton
noreply at git.blender.org
Mon Nov 17 14:53:44 CET 2014
Commit: 9c12ca22a5c1f9d5fd35b51c5f1b3f8f530e2547
Author: Campbell Barton
Date: Mon Nov 17 14:48:42 2014 +0100
Branches: mesh-transfer-data
https://developer.blender.org/rB9c12ca22a5c1f9d5fd35b51c5f1b3f8f530e2547
Mesh loop-island api: reuse the memory arena
===================================================================
M source/blender/blenkernel/BKE_mesh_mapping.h
M source/blender/blenkernel/intern/mesh_mapping.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h
index 0ae740a..41cb270 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -155,6 +155,7 @@ typedef struct MeshIslands {
void BKE_mesh_loop_islands_init(
MeshIslands *islands,
const short item_type, const int num_items, const short island_type);
+void BKE_mesh_loop_islands_clear(MeshIslands *islands);
void BKE_mesh_loop_islands_free(MeshIslands *islands);
void BKE_mesh_loop_islands_add(
MeshIslands *islands, const int num_items, int *item_indices,
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index 928d300..dee02c2 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -574,13 +574,16 @@ void BKE_mesh_loop_islands_init(
MeshIslands *islands,
const short item_type, const int num_items, const short island_type)
{
- MemArena *mem = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
+ MemArena *mem = islands->mem;
+
+ if (mem == NULL) {
+ mem = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
+ }
+ /* else memarena should be cleared */
BLI_assert(ELEM(item_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
BLI_assert(ELEM(island_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
- BKE_mesh_loop_islands_free(islands);
-
islands->item_type = item_type;
islands->nbr_items = num_items;
islands->items_to_islands_idx = BLI_memarena_alloc(mem, sizeof(*islands->items_to_islands_idx) * (size_t)num_items);
@@ -592,14 +595,8 @@ void BKE_mesh_loop_islands_init(
islands->mem = mem;
}
-void BKE_mesh_loop_islands_free(MeshIslands *islands)
+void BKE_mesh_loop_islands_clear(MeshIslands *islands)
{
- MemArena *mem = islands->mem;
-
- if (mem) {
- BLI_memarena_free(mem);
- }
-
islands->item_type = 0;
islands->nbr_items = 0;
islands->items_to_islands_idx = NULL;
@@ -608,10 +605,21 @@ void BKE_mesh_loop_islands_free(MeshIslands *islands)
islands->nbr_islands = 0;
islands->islands = NULL;
- islands->mem = NULL;
+ if (islands->mem) {
+ BLI_memarena_clear(islands->mem);
+ islands->mem = NULL;
+ }
+
islands->allocated_islands = 0;
}
+void BKE_mesh_loop_islands_free(MeshIslands *islands)
+{
+ if (islands->mem) {
+ BLI_memarena_free(islands->mem);
+ }
+}
+
void BKE_mesh_loop_islands_add(
MeshIslands *islands, const int num_items, int *items_indices,
const int num_island_items, int *island_item_indices)
@@ -679,7 +687,7 @@ bool BKE_mesh_calc_islands_loop_poly_uv(
int grp_idx, p_idx, pl_idx, l_idx;
- BKE_mesh_loop_islands_free(r_islands);
+ BKE_mesh_loop_islands_clear(r_islands);
BKE_mesh_loop_islands_init(r_islands, MISLAND_TYPE_LOOP, totloop, MISLAND_TYPE_POLY);
poly_loop_islands_calc(
More information about the Bf-blender-cvs
mailing list