Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-07-28 13:05:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-28 13:05:27 +0400
commit72f29170325e6c01afb667be209ea5939b445551 (patch)
treef90b3b8abe870095fad06178c31ed94289099276 /source/blender
parentb5890b35198add206e47b7edb523b7c4ff1fcf12 (diff)
bmesh: skip error checks when building in release mode (minor speedup),
also more strict use of BLI_array_declare(), only allow after array is declared.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_array.h9
-rw-r--r--source/blender/bmesh/intern/bmesh_core.c25
-rw-r--r--source/blender/bmesh/intern/bmesh_mods.c27
-rw-r--r--source/blender/bmesh/operators/bmo_dissolve.c4
-rw-r--r--source/blender/editors/mesh/editmesh_select.c4
5 files changed, 43 insertions, 26 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h
index 3fb50afdeac..252b37d9aae 100644
--- a/source/blender/blenlib/BLI_array.h
+++ b/source/blender/blenlib/BLI_array.h
@@ -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) \
diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c
index 05c462ac672..eac4b304b12 100644
--- a/source/blender/bmesh/intern/bmesh_core.c
+++ b/source/blender/bmesh/intern/bmesh_core.c
@@ -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) {
diff --git a/source/blender/bmesh/intern/bmesh_mods.c b/source/blender/bmesh/intern/bmesh_mods.c
index 77cb2717f84..418fc16ea55 100644
--- a/source/blender/bmesh/intern/bmesh_mods.c
+++ b/source/blender/bmesh/intern/bmesh_mods.c
@@ -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;
diff --git a/source/blender/bmesh/operators/bmo_dissolve.c b/source/blender/bmesh/operators/bmo_dissolve.c
index a3f67450380..d633182de42 100644
--- a/source/blender/bmesh/operators/bmo_dissolve.c
+++ b/source/blender/bmesh/operators/bmo_dissolve.c
@@ -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;
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 4ccb2a59b45..a1f1f6bd83f 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -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);