code cleanup: better use of BLI_array_* (grow in larger steps where possible), includ...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2012 02:17:57 +0000 (02:17 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2012 02:17:57 +0000 (02:17 +0000)
source/blender/blenlib/BLI_array.h
source/blender/bmesh/intern/bmesh_mods.c
source/blender/bmesh/intern/bmesh_mods.h
source/blender/bmesh/intern/bmesh_operator_api.h
source/blender/bmesh/operators/bmo_extrude.c
source/blender/bmesh/operators/bmo_inset.c
source/blender/bmesh/operators/bmo_subdivide.c
source/blender/bmesh/operators/bmo_triangulate.c
source/blender/bmesh/operators/bmo_utils.c

index b5ef7eb..d66b8c0 100644 (file)
@@ -69,7 +69,7 @@
 
 /* this returns the entire size of the array, including any buffering. */
 #define BLI_array_totalsize_dyn(arr)  (                                       \
-       ((arr)==NULL) ?                                                           \
+       ((arr) == NULL) ?                                                         \
            0 :                                                                   \
            MEM_allocN_len(arr) / sizeof(*arr)                                    \
 )
        }
 
 #define BLI_array_pop(arr)  (                                                 \
-       (arr&&_##arr##_count) ?                                                   \
+       (arr && _##arr##_count) ?                                                 \
            arr[--_##arr##_count] :                                               \
-           0                                                                     \
+           NULL                                                                  \
 )
 
 /* resets the logical size of an array to zero, but doesn't
index 3474d4b..a5e761a 100644 (file)
@@ -758,7 +758,7 @@ BMVert  *BM_edge_split_n(BMesh *bm, BMEdge *e, int numcuts)
 /**
  * Checks if a face is valid in the data structure
  */
-int BM_face_validate(BMesh *bm, BMFace *face, FILE *err)
+int BM_face_validate(BMFace *face, FILE *err)
 {
        BMIter iter;
        BLI_array_declare(verts);
@@ -771,10 +771,9 @@ int BM_face_validate(BMesh *bm, BMFace *face, FILE *err)
                fflush(err);
        }
 
-       for (l = BM_iter_new(&iter, bm, BM_LOOPS_OF_FACE, face); l; l = BM_iter_step(&iter)) {
-               BLI_array_growone(verts);
-               verts[BLI_array_count(verts) - 1] = l->v;
-               
+       BLI_array_growitems(verts, face->len);
+       BM_ITER_ELEM_INDEX (l, &iter, face, BM_LOOPS_OF_FACE, i) {
+               verts[i] = l->v;
                if (l->e->v1 == l->e->v2) {
                        fprintf(err, "Found bmesh edge with identical verts!\n");
                        fprintf(err, "  edge ptr: %p, vert: %p\n",  l->e, l->e->v1);
@@ -783,8 +782,8 @@ int BM_face_validate(BMesh *bm, BMFace *face, FILE *err)
                }
        }
 
-       for (i = 0; i < BLI_array_count(verts); i++) {
-               for (j = 0; j < BLI_array_count(verts); j++) {
+       for (i = 0; i < face->len; i++) {
+               for (j = 0; j < face->len; j++) {
                        if (j == i) {
                                continue;
                        }
index 2cb599f..802c6cc 100644 (file)
@@ -57,7 +57,7 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float perce
 
 BMVert *BM_edge_split_n(BMesh *bm, BMEdge *e, int numcuts);
 
-int     BM_face_validate(BMesh *bm, BMFace *face, FILE *err);
+int     BM_face_validate(BMFace *face, FILE *err);
 
 void    BM_edge_calc_rotate(BMEdge *e, int ccw,
                             BMLoop **r_l1, BMLoop **r_l2);
index b01b80f..bf66388 100644 (file)
@@ -413,8 +413,7 @@ void *BMO_iter_map_value_p(BMOIter *iter);
 float BMO_iter_map_value_f(BMOIter *iter);
 
 #define BMO_ITER(ele, iter, bm, op, slotname, restrict)   \
-       ele = BMO_iter_new(iter, bm, op, slotname, restrict); \
-       for ( ; ele; ele = BMO_iter_step(iter))
+       for (ele = BMO_iter_new(iter, bm, op, slotname, restrict); ele; ele = BMO_iter_step(iter))
 
 /******************* Inlined Functions********************/
 typedef void (*opexec)(BMesh *bm, BMOperator *op);
index db665c0..19e2dd8 100644 (file)
@@ -184,8 +184,7 @@ void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op)
        BMO_op_initf(bm, &dupeop, "dupe geom=%fve", EXT_INPUT);
        BMO_op_exec(bm, &dupeop);
 
-       e = BMO_iter_new(&siter, bm, &dupeop, "boundarymap", 0);
-       for ( ; e; e = BMO_iter_step(&siter)) {
+       for (e = BMO_iter_new(&siter, bm, &dupeop, "boundarymap", 0); e; e = BMO_iter_step(&siter)) {
                e2 = BMO_iter_map_value(&siter);
                e2 = *(BMEdge **)e2;
 
@@ -226,8 +225,7 @@ void bmo_extrude_vert_indiv_exec(BMesh *bm, BMOperator *op)
        BMVert *v, *dupev;
        BMEdge *e;
 
-       v = BMO_iter_new(&siter, bm, op, "verts", BM_VERT);
-       for ( ; v; v = BMO_iter_step(&siter)) {
+       for (v = BMO_iter_new(&siter, bm, op, "verts", BM_VERT); v; v = BMO_iter_step(&siter)) {
                dupev = BM_vert_create(bm, v->co, v);
 
                e = BM_edge_create(bm, v, dupev, NULL, FALSE);
@@ -343,8 +341,8 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op)
        }
        
        BMO_slot_copy(&dupeop, op, "newout", "geomout");
-       e = BMO_iter_new(&siter, bm, &dupeop, "boundarymap", 0);
-       for ( ; e; e = BMO_iter_step(&siter)) {
+
+       for (e = BMO_iter_new(&siter, bm, &dupeop, "boundarymap", 0); e; e = BMO_iter_step(&siter)) {
 
                /* this should always be wire, so this is mainly a speedup to avoid map lookup */
                if (BM_edge_is_wire(e) && BMO_slot_map_contains(bm, op, "exclude", e)) {
@@ -389,8 +387,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op)
        }
 
        /* link isolated vert */
-       v = BMO_iter_new(&siter, bm, &dupeop, "isovertmap", 0);
-       for ( ; v; v = BMO_iter_step(&siter)) {
+       for (v = BMO_iter_new(&siter, bm, &dupeop, "isovertmap", 0); v; v = BMO_iter_step(&siter)) {
                v2 = *((void **)BMO_iter_map_value(&siter));
                BM_edge_create(bm, v, v2, v->e, TRUE);
        }
index 6e3024c..ee52f8b 100644 (file)
@@ -524,8 +524,8 @@ void bmo_inset_exec(BMesh *bm, BMOperator *op)
                BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) {
                        if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
                                const float fac = (depth *
-                                                                  (use_relative_offset ? bm_vert_avg_tag_dist(v) : 1.0f) *
-                                                                  (use_even_boundry    ? BM_vert_calc_shell_factor(v) : 1.0f));
+                                                  (use_relative_offset ? bm_vert_avg_tag_dist(v) : 1.0f) *
+                                                  (use_even_boundry    ? BM_vert_calc_shell_factor(v) : 1.0f));
                                madd_v3_v3v3fl(varr_co[i], v->co, v->no, fac);
                        }
                }
index d629585..e2f00e3 100644 (file)
@@ -1042,9 +1042,8 @@ void BM_mesh_esubdivideflag(Object *UNUSED(obedit), BMesh *bm, int flag, float s
                BMOIter iter;
                BMElem *ele;
                // int i;
-               
-               ele = BMO_iter_new(&iter, bm, &op, "outinner", BM_EDGE|BM_VERT);
-               for ( ; ele; ele = BMO_iter_step(&iter)) {
+
+               for (ele = BMO_iter_new(&iter, bm, &op, "outinner", BM_EDGE | BM_VERT); ele; ele = BMO_iter_step(&iter)) {
                        BM_elem_select_set(bm, ele, TRUE);
                }
        }
@@ -1056,8 +1055,7 @@ void BM_mesh_esubdivideflag(Object *UNUSED(obedit), BMesh *bm, int flag, float s
                /* deselect input */
                BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, FALSE);
 
-               ele = BMO_iter_new(&iter, bm, &op, "outinner", BM_EDGE|BM_VERT);
-               for ( ; ele; ele = BMO_iter_step(&iter)) {
+               for (ele = BMO_iter_new(&iter, bm, &op, "outinner", BM_EDGE | BM_VERT); ele; ele = BMO_iter_step(&iter)) {
                        BM_elem_select_set(bm, ele, TRUE);
 
                        if (ele->head.htype == BM_VERT) {
index 916b10d..7fd6cf6 100644 (file)
@@ -51,21 +51,16 @@ void bmo_triangulate_exec(BMesh *bm, BMOperator *op)
        BLI_array_declare(newfaces);
        float (*projectverts)[3] = NULL;
        BLI_array_declare(projectverts);
-       int i, lastlen = 0 /* , count = 0 */;
+       int i;
        const int use_beauty = BMO_slot_bool_get(op, "use_beauty");
 
-       face = BMO_iter_new(&siter, bm, op, "faces", BM_FACE);
-       for ( ; face; face = BMO_iter_step(&siter)) {
-               if (lastlen < face->len) {
-                       BLI_array_empty(projectverts);
-                       BLI_array_empty(newfaces);
-                       for (lastlen = 0; lastlen < face->len; lastlen++) {
-                               BLI_array_growone(projectverts);
-                               BLI_array_growone(projectverts);
-                               BLI_array_growone(projectverts);
-                               BLI_array_growone(newfaces);
-                       }
-               }
+       for (face = BMO_iter_new(&siter, bm, op, "faces", BM_FACE); face; face = BMO_iter_step(&siter)) {
+
+               BLI_array_empty(projectverts);
+               BLI_array_empty(newfaces);
+
+               BLI_array_growitems(projectverts, face->len * 3);
+               BLI_array_growitems(newfaces, face->len);
 
                BM_face_triangulate(bm, face, projectverts, EDGE_NEW, FACE_NEW, newfaces, use_beauty);
 
index 801fa20..3cfa70f 100644 (file)
@@ -1046,12 +1046,10 @@ void bmo_face_reverseuvs_exec(BMesh *bm, BMOperator *op)
 
                        /* now that we have the uvs in the array, reverse! */
                        i = 0;
-                       BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
+                       BM_ITER_ELEM_INDEX (lf, &l_iter, fs, BM_LOOPS_OF_FACE, i) {
                                /* current loop uv is the previous loop uv */
                                MLoopUV *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPUV);
-                               luv->uv[0] = uvs[(fs->len - i - 1)][0];
-                               luv->uv[1] = uvs[(fs->len - i - 1)][1];
-                               i++;
+                               copy_v2_v2(luv->uv, uvs[(fs->len - i - 1)]);
                        }
                }
        }
@@ -1140,25 +1138,20 @@ void bmo_face_reversecolors_exec(BMesh *bm, BMOperator *op)
        BMO_ITER (fs, &fs_iter, bm, op, "faces", BM_FACE) {
                if (CustomData_has_layer(&(bm->ldata), CD_MLOOPCOL)) {
                        BMLoop *lf;     /* current face loops */
-                       int i = 0;
+                       int i;
 
                        BLI_array_empty(cols);
-                       BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
-                               MLoopCol *lcol = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL);
+                       BLI_array_growitems(cols, fs->len);
 
-                               /* current loop uv is the previous loop color */
-                               BLI_array_growone(cols);
-                               cols[i] = *lcol;
-                               i++;
+                       BM_ITER_ELEM_INDEX (lf, &l_iter, fs, BM_LOOPS_OF_FACE, i) {
+                               cols[i] = *((MLoopCol *)CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL));
                        }
 
                        /* now that we have the uvs in the array, reverse! */
-                       i = 0;
-                       BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
+                       BM_ITER_ELEM_INDEX (lf, &l_iter, fs, BM_LOOPS_OF_FACE, i) {
                                /* current loop uv is the previous loop color */
                                MLoopCol *lcol = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL);
                                *lcol = cols[(fs->len - i - 1)];
-                               i++;
                        }
                }
        }