bmesh: skip error checks when building in release mode (minor speedup),
authorCampbell Barton <ideasman42@gmail.com>
Sun, 28 Jul 2013 09:05:27 +0000 (09:05 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 28 Jul 2013 09:05:27 +0000 (09:05 +0000)
also more strict use of BLI_array_declare(), only allow after array is declared.

source/blender/blenlib/BLI_array.h
source/blender/bmesh/intern/bmesh_core.c
source/blender/bmesh/intern/bmesh_mods.c
source/blender/bmesh/operators/bmo_dissolve.c
source/blender/editors/mesh/editmesh_select.c

index 3fb50afdeac396dddd01fb7831d102cd929806ba..252b37d9aae1025ce5560e679e7f18399f1d10ea 100644 (file)
@@ -66,8 +66,9 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static,
 /* -------------------------------------------------------------------- */
 /* public defines */
 
+/* use sizeof(*arr) to ensure the array exists and is an array */
 #define BLI_array_declare(arr)                                                \
-       int   _##arr##_count = 0;                                                 \
+       int   _##arr##_count = ((void)(sizeof(*arr)), 0);                         \
        void *_##arr##_static = NULL
 
 /* this will use stack space, up to maxstatic array elements, before
@@ -148,8 +149,8 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static,
 
 /* only to prevent unused warnings */
 #define BLI_array_fake_user(arr)                                              \
-       (void)_##arr##_count,                                                     \
-       (void)_##arr##_static
+       ((void)_##arr##_count,                                                    \
+        (void)_##arr##_static)
 
 
 /* -------------------------------------------------------------------- */
@@ -161,7 +162,7 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static,
  * but use when the max size is known ahead of time */
 #define BLI_array_fixedstack_declare(arr, maxstatic, realsize, allocstr)      \
        char _##arr##_static[maxstatic * sizeof(*(arr))];                         \
-       const int _##arr##_is_static = ((void *)_##arr##_static) != (             \
+       const bool _##arr##_is_static = ((void *)_##arr##_static) != (            \
            arr = ((realsize) <= maxstatic) ?                                     \
                (void *)_##arr##_static :                                         \
                MEM_mallocN(sizeof(*(arr)) * (realsize), allocstr)                \
index 05c462ac672df3bac91a9663e7fb319ba8eb9005..eac4b304b12600af8772a50961ef905a8a7788db 100644 (file)
@@ -1368,16 +1368,20 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e)
        BMLoop *l_next;
        BMEdge *e_new;
        BMVert *v_new, *v_old;
-       int i, valence1 = 0, valence2 = 0;
+#ifndef NDEBUG
+       int valence1, valence2;
        bool edok;
+       int i;
+#endif
 
        BLI_assert(bmesh_vert_in_edge(e, tv) != false);
 
        v_old = bmesh_edge_other_vert_get(e, tv);
 
+#ifndef NDEBUG
        valence1 = bmesh_disk_count(v_old);
-
        valence2 = bmesh_disk_count(tv);
+#endif
 
        v_new = BM_vert_create(bm, tv->co, tv, 0);
        e_new = BM_edge_create(bm, v_new, tv, e, 0);
@@ -1400,6 +1404,7 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e)
        /* add e_new to tv's disk cycle */
        bmesh_disk_edge_append(e_new, tv);
 
+#ifndef NDEBUG
        /* verify disk cycles */
        edok = bmesh_disk_validate(valence1, v_old->e, v_old);
        BMESH_ASSERT(edok != false);
@@ -1407,6 +1412,7 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e)
        BMESH_ASSERT(edok != false);
        edok = bmesh_disk_validate(2, v_new->e, v_new);
        BMESH_ASSERT(edok != false);
+#endif
 
        /* Split the radial cycle if present */
        l_next = e->l;
@@ -1470,6 +1476,7 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e)
 
                }
 
+#ifndef NDEBUG
                /* verify length of radial cycle */
                edok = bmesh_radial_validate(radlen, e->l);
                BMESH_ASSERT(edok != false);
@@ -1508,6 +1515,7 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e)
                        BM_CHECK_ELEMENT(l->e);
                        BM_CHECK_ELEMENT(l->f);
                }
+#endif
        }
 
        BM_CHECK_ELEMENT(e_new);
@@ -1555,8 +1563,8 @@ BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_e
 {
        BMEdge *e_old;
        BMVert *v_old, *tv;
-       BMLoop *l_kill, *l;
-       int len, radlen = 0, i, valence1, valence2;
+       BMLoop *l_kill;
+       int len, radlen = 0, i;
        bool edok, halt = false;
 
        if (bmesh_vert_in_edge(e_kill, v_kill) == 0) {
@@ -1566,6 +1574,11 @@ BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_e
        len = bmesh_disk_count(v_kill);
        
        if (len == 2) {
+#ifndef NDEBUG
+               int valence1, valence2;
+               BMLoop *l;
+#endif
+
                e_old = bmesh_disk_edge_next(e_kill, v_kill);
                tv = bmesh_edge_other_vert_get(e_kill, v_kill);
                v_old = bmesh_edge_other_vert_get(e_old, v_kill);
@@ -1577,9 +1590,11 @@ BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_e
                else {
                        BMEdge *e_splice;
 
+#ifndef NDEBUG
                        /* For verification later, count valence of v_old and tv */
                        valence1 = bmesh_disk_count(v_old);
                        valence2 = bmesh_disk_count(tv);
+#endif
 
                        if (check_edge_double) {
                                e_splice = BM_edge_exists(tv, v_old);
@@ -1645,6 +1660,7 @@ BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_e
                        /* deallocate vertex */
                        bm_kill_only_vert(bm, v_kill);
 
+#ifndef NDEBUG
                        /* Validate disk cycle lengths of v_old, tv are unchanged */
                        edok = bmesh_disk_validate(valence1, v_old->e, v_old);
                        BMESH_ASSERT(edok != false);
@@ -1664,6 +1680,7 @@ BMEdge *bmesh_jekv(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool check_e
                                BM_CHECK_ELEMENT(l->e);
                                BM_CHECK_ELEMENT(l->f);
                        }
+#endif
 
                        if (check_edge_double) {
                                if (e_splice) {
index 77cb2717f8419201f57d97eeba10dfa6197b8bb0..418fc16ea558cc9f8395a4a524b0fb3254838f97 100644 (file)
@@ -490,26 +490,22 @@ BMEdge *BM_vert_collapse_faces(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, float
        BMEdge *e2;
        BMVert *tv2;
 
-       BMIter iter;
-       BMLoop *l_iter = NULL, *kvloop = NULL, *tvloop = NULL;
-
-       void *src[2];
-       float w[2];
-
        /* Only intended to be called for 2-valence vertices */
        BLI_assert(bmesh_disk_count(v_kill) <= 2);
 
 
-       /* first modify the face loop data  */
-       w[0] = 1.0f - fac;
-       w[1] = fac;
+       /* first modify the face loop data */
 
        if (e_kill->l) {
+               BMLoop *l_iter;
+               const float w[2] = {1.0f - fac, fac};
+
                l_iter = e_kill->l;
                do {
                        if (l_iter->v == tv && l_iter->next->v == v_kill) {
-                               tvloop = l_iter;
-                               kvloop = l_iter->next;
+                               void *src[2];
+                               BMLoop *tvloop = l_iter;
+                               BMLoop *kvloop = l_iter->next;
 
                                src[0] = kvloop->head.data;
                                src[1] = tvloop->head.data;
@@ -525,11 +521,12 @@ BMEdge *BM_vert_collapse_faces(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, float
        tv2 = BM_edge_other_vert(e2, v_kill);
 
        if (join_faces) {
+               BMIter fiter;
                BMFace **faces = NULL;
                BMFace *f;
-               BLI_array_staticdeclare(faces, 8);
+               BLI_array_staticdeclare(faces, BM_DEFAULT_ITER_STACK_SIZE);
 
-               BM_ITER_ELEM (f, &iter, v_kill, BM_FACES_OF_VERT) {
+               BM_ITER_ELEM (f, &fiter, v_kill, BM_FACES_OF_VERT) {
                        BLI_array_append(faces, f);
                }
 
@@ -543,6 +540,8 @@ BMEdge *BM_vert_collapse_faces(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, float
                        }
                }
 
+               BLI_assert(BLI_array_count(faces) < 8);
+
                BLI_array_free(faces);
        }
        else {
@@ -553,8 +552,8 @@ BMEdge *BM_vert_collapse_faces(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, float
                /* e_new = BM_edge_exists(tv, tv2); */ /* same as return above */
 
                if (e_new && kill_degenerate_faces) {
-                       BLI_array_declare(bad_faces);
                        BMFace **bad_faces = NULL;
+                       BLI_array_staticdeclare(bad_faces, BM_DEFAULT_ITER_STACK_SIZE);
 
                        BMIter fiter;
                        BMFace *f;
index a3f674503806e87d95045a75b3ad454b99926d18..d633182de425f9dda62ad18a2ed624d752578970 100644 (file)
@@ -103,10 +103,10 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op)
 {
        BMOIter oiter;
        BMFace *f;
-       BLI_array_declare(faces);
-       BLI_array_declare(regions);
        BMFace ***regions = NULL;
        BMFace **faces = NULL;
+       BLI_array_declare(regions);
+       BLI_array_declare(faces);
        BMFace *act_face = bm->act_face;
        BMWalker regwalker;
        int i;
index 4ccb2a59b45e6c52b36e2d4aee7652aeaea15f3a..a1f1f6bd83fde871ed1eaaff41c8471c37d88a2e 100644 (file)
@@ -3074,10 +3074,10 @@ void MESH_OT_region_to_loop(wmOperatorType *ot)
 static int loop_find_region(BMLoop *l, int flag,
                             SmallHash *fhash, BMFace ***region_out)
 {
-       BLI_array_declare(region);
-       BLI_array_declare(stack);
        BMFace **region = NULL;
        BMFace **stack = NULL;
+       BLI_array_declare(region);
+       BLI_array_declare(stack);
        BMFace *f;
        
        BLI_array_append(stack, l->f);