Cleanup: use BLI_listbase_count_ex to avoid redundant looping
authorCampbell Barton <ideasman42@gmail.com>
Sun, 16 Nov 2014 13:23:37 +0000 (14:23 +0100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 16 Nov 2014 13:23:37 +0000 (14:23 +0100)
13 files changed:
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/softbody.c
source/blender/blenlib/intern/listbase.c
source/blender/bmesh/tools/bmesh_region_match.c
source/blender/collada/ArmatureExporter.cpp
source/blender/editors/armature/editarmature_retarget.c
source/blender/editors/armature/reeb.c
source/blender/editors/mesh/editmesh_knife.c
source/blender/editors/space_buttons/buttons_texture.c
source/blender/editors/space_nla/nla_edit.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/BL_SkinDeformer.cpp

index 95dfc8a3e4bc868f4388aa45db4fc435e2c979ec..725ed8d2a3e2982c3ccaa49f1b925ba203b130a8 100644 (file)
@@ -1098,7 +1098,7 @@ bool BKE_object_lod_remove(Object *ob, int level)
        MEM_freeN(rem);
 
        /* If there are no user defined lods, remove the base lod as well */
-       if (BLI_listbase_count(&ob->lodlevels) == 1) {
+       if (BLI_listbase_is_single(&ob->lodlevels)) {
                LodLevel *base = ob->lodlevels.first;
                BLI_remlink(&ob->lodlevels, base);
                MEM_freeN(base);
index a17d0cae3235213905872b4106ca6d32bdef9cb3..bfb780244783f2a1ffd34edcdef0f64af4e40a84 100644 (file)
@@ -3513,7 +3513,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n
 
        psys->part = psys_new_settings(DATA_("ParticleSettings"), NULL);
 
-       if (BLI_listbase_count(&ob->particlesystem) > 1)
+       if (BLI_listbase_count_ex(&ob->particlesystem, 2) > 1)
                BLI_snprintf(psys->name, sizeof(psys->name), DATA_("ParticleSystem %i"), BLI_listbase_count(&ob->particlesystem));
        else
                BLI_strncpy(psys->name, DATA_("ParticleSystem"), sizeof(psys->name));
index de95653f659e205df6d673fd87adcf6fc22856ac..941344cf21ea13c39eba683542c6ae2d18bd5eda 100644 (file)
@@ -3561,7 +3561,7 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob)
 
        if (ob->softflag & OB_SB_EDGES) {
                if (ob->type==OB_CURVE) {
-                       totspring= totvert - BLI_listbase_count(&cu->nurb);
+                       totspring = totvert - BLI_listbase_count(&cu->nurb);
                }
        }
 
index ea33b9b1e3b4b94d4684ba67dbf45559254a8d1f..bd3e1e0bbb012a452cf3837cc41d72793a6b6b63 100644 (file)
@@ -372,6 +372,11 @@ void BLI_freelistN(ListBase *listbase)
        BLI_listbase_clear(listbase);
 }
 
+/**
+ * Returns the number of elements in \a listbase, up until (and including count_max)
+ *
+ * \note Use to avoid redundant looping.
+ */
 int BLI_listbase_count_ex(const ListBase *listbase, const int count_max)
 {
        Link *link;
index 562f123ef4b881b39fd471a043f6a0ad6bdc07ea..bb7000e553496b45330db5f58c34483f6f50d29a 100644 (file)
@@ -656,7 +656,7 @@ static bool bm_uuidwalk_facestep_begin(
        bool ok = false;
 
        BLI_assert(BLI_ghash_size(uuidwalk->cache.faces_from_uuid) == 0);
-       BLI_assert(BLI_listbase_count(&fstep->items) == 0);
+       BLI_assert(BLI_listbase_is_empty(&fstep->items));
 
        f_link_prev_p = &fstep->faces;
        for (f_link = fstep->faces; f_link; f_link = f_link_next) {
index e50cd6ff28928381c3627063d0ff30c1a477f8d1..5ce62873377b220d9a52c34dd8adf6adbe3c22c4 100644 (file)
@@ -168,7 +168,7 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce,
                node.setNodeSid(node_sid);
 
 #if 0 
-               if (BLI_listbase_is_empty(&bone->childbase) || BLI_listbase_count(&(bone->childbase)) >= 2) {
+               if (BLI_listbase_is_empty(&bone->childbase) || BLI_listbase_count_ex(&bone->childbase, 2) == 2) {
                        add_blender_leaf_bone( bone, ob_arm, node);
                }
                else {
index d1cab01a2f64965d764639d1c238352559f9f70f..aace8c5434c264e9810f581c899c5cc95bb7e423 100644 (file)
@@ -1205,7 +1205,7 @@ static void RIG_arcFromBoneChain(RigGraph *rg, ListBase *list, EditBone *root_bo
 static void RIG_findHead(RigGraph *rg)
 {
        if (rg->head == NULL) {
-               if (BLI_listbase_count(&rg->arcs) == 1) {
+               if (BLI_listbase_is_single(&rg->arcs)) {
                        RigArc *arc = rg->arcs.first;
                        
                        rg->head = (RigNode *)arc->head;
@@ -2152,7 +2152,7 @@ void exec_retargetArctoArc(TaskPool *UNUSED(pool), void *taskdata, int UNUSED(th
        RigNode *inode_start = p->inode_start;
        ReebArc *earc = iarc->link_mesh;
        
-       if (BLI_listbase_count(&iarc->edges) == 1) {
+       if (BLI_listbase_is_single(&iarc->edges)) {
                RigEdge *edge = iarc->edges.first;
 
                if (testFlipArc(iarc, inode_start)) {
index dd2212745e019e3a20fad429abf751c32c982c2f..f29d15ff4162aed9db0d882bf41a0af2b9007f7d 100644 (file)
@@ -2460,7 +2460,7 @@ void renormalizeWeight(EditMesh *em, float newmax)
        EditVert *eve;
        float minimum, maximum, range;
        
-       if (em == NULL || BLI_listbase_count(&em->verts) == 0)
+       if (em == NULL || BLI_listbase_is_empty(&em->verts))
                return;
 
        /* First pass, determine maximum and minimum */
@@ -2486,7 +2486,7 @@ int weightFromLoc(EditMesh *em, int axis)
 {
        EditVert *eve;
        
-       if (em == NULL || BLI_listbase_count(&em->verts) == 0 || axis < 0 || axis > 2)
+       if (em == NULL || BLI_listbase_is_empty(&em->verts) || axis < 0 || axis > 2)
                return 0;
 
        /* Copy coordinate in weight */
index dccb1f14af6b6c5609ec39754673084c4bf70ea6..6246abda1258b8bbbc93d1f27e73e2402288d782 100644 (file)
@@ -749,12 +749,8 @@ static void knife_cut_face(KnifeTool_OpData *kcd, BMFace *f, ListBase *hits)
 {
        Ref *r;
        KnifeLineHit *lh, *prevlh;
-       int n;
 
-       (void) kcd;
-
-       n = BLI_listbase_count(hits);
-       if (n < 2)
+       if (BLI_listbase_count_ex(hits, 2) != 2)
                return;
 
        prevlh = NULL;
@@ -2108,7 +2104,7 @@ static ListBase *find_chain(KnifeTool_OpData *kcd, ListBase *fedges)
                        break;
        }
        if (ans) {
-               BLI_assert(BLI_listbase_count(ans) > 0);
+               BLI_assert(!BLI_listbase_is_empty(ans));
                for (r = ans->first; r; r = r->next) {
                        ref = find_ref(fedges, r->ref);
                        BLI_assert(ref != NULL);
index c8cbf0f579434fdb2553fb9e8e41ea20730741ce..3b939702c584f0e8d295f4c902105fc0d0e6b293 100644 (file)
@@ -468,7 +468,7 @@ void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
        }
        else {
                /* set one user as active based on active index */
-               if (ct->index >= BLI_listbase_count(&ct->users))
+               if (ct->index == BLI_listbase_count_ex(&ct->users, ct->index))
                        ct->index = 0;
 
                ct->user = BLI_findlink(&ct->users, ct->index);
index 37efe1afcf511fa94ec3c3dbd68153b9472b8deb..f43982fac8b337d20a1fddc78802373721e2b4bc 100644 (file)
@@ -1436,7 +1436,9 @@ static int nlaedit_swap_exec(bContext *C, wmOperator *op)
                if (BLI_listbase_is_empty(&nlt->strips) == false) {
                        NlaStrip *mstrip = (NlaStrip *)nlt->strips.first;
                        
-                       if ((mstrip->flag & NLASTRIP_FLAG_TEMP_META) && (BLI_listbase_count(&mstrip->strips) == 2)) {
+                       if ((mstrip->flag & NLASTRIP_FLAG_TEMP_META) &&
+                           (BLI_listbase_count_ex(&mstrip->strips, 3) == 2))
+                       {
                                /* remove this temp meta, so that we can see the strips inside */
                                BKE_nlastrips_clear_metas(&nlt->strips, 0, 1);
                        }
index 246d823ce90174431153579d7b9d5024bcd1df4b..c6140743950efe636b1bb16571e6e751a735a68c 100644 (file)
@@ -1568,7 +1568,7 @@ static KX_GameObject *gameobject_from_blenderobject(
                gameobj->AddMesh(meshobj);
 
                // gather levels of detail
-               if (BLI_listbase_count(&ob->lodlevels) > 1) {
+               if (BLI_listbase_count_ex(&ob->lodlevels, 2) > 1) {
                        LodLevel *lod = ((LodLevel*)ob->lodlevels.first)->next;
                        Mesh* lodmesh = mesh;
                        Object* lodmatob = ob;
index bf5e3860e16fdbcc8ff3a932b76afa5287da1c8b..950c1dcad11f313047d74fcc4c9d9620f5b992cd 100644 (file)
@@ -200,12 +200,14 @@ void BL_SkinDeformer::BGEDeformVerts()
        Object *par_arma = m_armobj->GetArmatureObject();
        MDeformVert *dverts = m_bmesh->dvert;
        bDeformGroup *dg;
-       int defbase_tot = BLI_listbase_count(&m_objMesh->defbase);
+       int defbase_tot;
        Eigen::Matrix4f pre_mat, post_mat, chan_mat, norm_chan_mat;
 
        if (!dverts)
                return;
 
+       defbase_tot = BLI_listbase_count(&m_objMesh->defbase);
+
        if (m_dfnrToPC == NULL)
        {
                m_dfnrToPC = new bPoseChannel*[defbase_tot];