diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-12 16:23:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-12 16:23:44 +0400 |
commit | 40535f5ef3baaef5ba4d8c1f7abbbb7f1efe3b77 (patch) | |
tree | 0c8e44aa35aee81be56ddb451437147e6b816a0a | |
parent | 85145db47be6a4b117142ca5370ed0e10104a5cb (diff) |
bmesh recalculate normals - remove BLI_array reallocation, the max size of the array is known.
replace with STACK_* macros (moved to BLI_utildefines.h).
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 8 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_core.c | 13 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_utils.c | 28 |
3 files changed, 17 insertions, 32 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 1a0073a8f13..a51dcfe197c 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -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))) diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 92bab258d5c..56ac6c379c2 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -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; } diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c index 7e86c0a52ea..c84d8716804 100644 --- a/source/blender/bmesh/operators/bmo_utils.c +++ b/source/blender/bmesh/operators/bmo_utils.c @@ -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) { |