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 /source/blender/bmesh/operators | |
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).
Diffstat (limited to 'source/blender/bmesh/operators')
-rw-r--r-- | source/blender/bmesh/operators/bmo_utils.c | 28 |
1 files changed, 8 insertions, 20 deletions
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) { |