BMesh: collapse_uvs - avoid clearing and flagging for every cd-layer
authorCampbell Barton <ideasman42@gmail.com>
Wed, 22 Jan 2014 06:11:46 +0000 (17:11 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 22 Jan 2014 06:16:38 +0000 (17:16 +1100)
source/blender/bmesh/operators/bmo_removedoubles.c

index 04831b8f021f8d1c4fdfd9267bf3afb2aa49d5a1..cef7c70d52031df6cdc5e5ebea0e87c148418018 100644 (file)
@@ -443,7 +443,7 @@ void bmo_collapse_exec(BMesh *bm, BMOperator *op)
 }
 
 /* uv collapse function */
-static void bmo_collapsecon_do_layer(BMesh *bm, BMOperator *op, int layer)
+static void bmo_collapsecon_do_layer(BMesh *bm, const int layer, const short oflag)
 {
        BMIter iter, liter;
        BMFace *f;
@@ -454,19 +454,14 @@ static void bmo_collapsecon_do_layer(BMesh *bm, BMOperator *op, int layer)
        CDBlockBytes min, max;
        int i, tot, type = bm->ldata.layers[layer].type;
 
-       /* clear all short flags */
-       BMO_mesh_flag_disable_all(bm, op, BM_ALL, (1 << 16) - 1);
-
-       BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, EDGE_MARK);
-
        BMW_init(&walker, bm, BMW_LOOPDATA_ISLAND,
-                BMW_MASK_NOP, EDGE_MARK, BMW_MASK_NOP,
+                BMW_MASK_NOP, oflag, BMW_MASK_NOP,
                 BMW_FLAG_NOP, /* no need to use BMW_FLAG_TEST_HIDDEN, already marked data */
                 layer);
 
        BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
                BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
-                       if (BMO_elem_flag_test(bm, l->e, EDGE_MARK)) {
+                       if (BMO_elem_flag_test(bm, l->e, oflag)) {
                                /* walk */
                                BLI_array_empty(blocks);
 
@@ -497,12 +492,33 @@ static void bmo_collapsecon_do_layer(BMesh *bm, BMOperator *op, int layer)
 
 void bmo_collapse_uvs_exec(BMesh *bm, BMOperator *op)
 {
+       const short oflag = EDGE_MARK;
        int i;
 
+       /* check flags dont change once set */
+#ifndef NDEBUG
+       int tot_test;
+#endif
+
+       if (!CustomData_has_math(&bm->ldata)) {
+               return;
+       }
+
+       BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, oflag);
+
+#ifndef NDEBUG
+       tot_test = BM_iter_mesh_count_flag(BM_EDGES_OF_MESH, bm, oflag, true);
+#endif
+
        for (i = 0; i < bm->ldata.totlayer; i++) {
                if (CustomData_layer_has_math(&bm->ldata, i))
-                       bmo_collapsecon_do_layer(bm, op, i);
+                       bmo_collapsecon_do_layer(bm, i, oflag);
        }
+
+#ifndef NDEBUG
+       BLI_assert(tot_test == BM_iter_mesh_count_flag(BM_EDGES_OF_MESH, bm, EDGE_MARK, true));
+#endif
+
 }
 
 static void bmesh_find_doubles_common(BMesh *bm, BMOperator *op,