bmesh recalculate normals - remove BLI_array reallocation, the max size of the array is known.

replace with STACK_* macros (moved to BLI_utildefines.h).
This commit is contained in:
Campbell Barton
2013-05-12 12:23:44 +00:00
parent 85145db47b
commit 40535f5ef3
3 changed files with 17 additions and 32 deletions

View File

@@ -290,6 +290,14 @@ typedef bool _BLI_Bool;
#define UNPACK3OP(op, a) op((a)[0]), op((a)[1]), op((a)[2])
#define UNPACK4OP(op, a) op((a)[0]), op((a)[1]), op((a)[2]), op((a)[3])
/* simple stack */
#define STACK_DECLARE(stack) unsigned int _##stack##_index
#define STACK_INIT(stack) ((void)stack, (void)((_##stack##_index) = 0))
#define STACK_SIZE(stack) ((void)stack, (void)(_##stack##_index))
#define STACK_PUSH(stack, val) (void)((stack)[(_##stack##_index)++] = val)
#define STACK_POP(stack) ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : NULL)
#define STACK_FREE(stack) ((void)stack)
/* array helpers */
#define ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot) \
(arr_dtype *)((char *)arr_start + (elem_size * (tot - 1)))

View File

@@ -1893,13 +1893,7 @@ bool bmesh_vert_separate(BMesh *bm, BMVert *v, BMVert ***r_vout, int *r_vout_len
{
const int v_edgetot = BM_vert_face_count(v);
BMEdge **stack = BLI_array_alloca(stack, v_edgetot);
unsigned int _stack_i;
/* */
#define STACK_INIT(stack) ((void)stack, (void)(_stack_i = 0))
#define STACK_PUSH(stack, val) (void)((stack)[_stack_i++] = val)
#define STACK_POP(stack) ((void)0, (_stack_i ? ((stack)[--_stack_i]) : NULL))
#define STACK_FREE(stack) ((void)stack)
STACK_DECLARE(stack);
SmallHash visithash;
BMVert **verts = NULL;
@@ -2020,11 +2014,6 @@ bool bmesh_vert_separate(BMesh *bm, BMVert *v, BMVert ***r_vout, int *r_vout_len
*r_vout = verts;
}
#undef STACK_INIT
#undef STACK_PUSH
#undef STACK_POP
#undef STACK_FREE
return true;
}

View File

@@ -310,11 +310,11 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op)
{
BMIter liter, liter2;
BMOIter siter;
BMFace *f, *startf, **fstack = NULL;
BLI_array_declare(fstack);
BMFace *f, *startf;
BMFace **fstack = MEM_mallocN(sizeof(*fstack) * BMO_slot_buffer_count(op->slots_in, "faces"), __func__);
STACK_DECLARE(fstack);
BMLoop *l, *l2;
float maxx, maxx_test, cent[3];
int i, i_max;
const bool use_flip = BMO_slot_bool_get(op->slots_in, "use_face_tag");
startf = NULL;
@@ -359,16 +359,10 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op)
* stack (if we use simple function recursion, we'd end up overloading
* the stack on large meshes). */
BLI_array_grow_one(fstack);
fstack[0] = startf;
STACK_PUSH(fstack, startf);
BMO_elem_flag_enable(bm, startf, FACE_VIS);
i = 0;
i_max = 1;
while (i >= 0) {
f = fstack[i];
i--;
while ((f = STACK_POP(fstack))) {
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
BM_ITER_ELEM (l2, &liter2, l, BM_LOOPS_OF_LOOP) {
if (!BMO_elem_flag_test(bm, l2->f, FACE_FLAG) || l2 == l)
@@ -376,8 +370,7 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op)
if (!BMO_elem_flag_test(bm, l2->f, FACE_VIS)) {
BMO_elem_flag_enable(bm, l2->f, FACE_VIS);
i++;
if (l2->v == l->v) {
BM_face_normal_flip(bm, l2->f);
@@ -392,18 +385,13 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op)
}
}
if (i == i_max) {
BLI_array_grow_one(fstack);
i_max++;
}
fstack[i] = l2->f;
STACK_PUSH(fstack, l2->f);
}
}
}
}
BLI_array_free(fstack);
MEM_freeN(fstack);
/* check if we have faces yet to do. if so, recurse */
BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) {