remove inline loops in a few places
authorCampbell Barton <ideasman42@gmail.com>
Sun, 22 Aug 2010 14:15:28 +0000 (14:15 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 22 Aug 2010 14:15:28 +0000 (14:15 +0000)
replace with defgroup_find_name() and BLI_findstring()

13 files changed:
source/blender/blenkernel/BKE_deform.h
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/context.c
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/key.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/property.c
source/blender/editors/animation/keyingsets.c
source/blender/editors/armature/editarmature.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/object/object_vgroup.c
source/blender/makesrna/intern/rna_object.c

index 702cb100e18d5cb6c1710a24b88859812deb3adf..53f474aa97247e304d8b94044f9788174c530d92 100644 (file)
@@ -42,7 +42,7 @@ struct MDeformVert;
 
 void                            defgroup_copy_list(struct ListBase *lb1, struct ListBase *lb2);
 struct bDeformGroup *defgroup_duplicate(struct bDeformGroup *ingroup);
-struct bDeformGroup *defgroup_find_name(struct Object *ob, char *name);
+struct bDeformGroup *defgroup_find_name(struct Object *ob, const char *name);
 int                                     defgroup_find_index(struct Object *ob, struct bDeformGroup *dg);
 int                                    *defgroup_flip_map(struct Object *ob, int use_default);
 int                                     defgroup_flip_index(struct Object *ob, int index, int use_default);
index 41ff3fed8a579f2fdb7694f67c5409703d22171d..90a3a6ce6643b66595086480a15ee992e4b9efac 100644 (file)
@@ -368,20 +368,12 @@ void action_groups_remove_channel (bAction *act, FCurve *fcu)
 /* Find a group with the given name */
 bActionGroup *action_groups_find_named (bAction *act, const char name[])
 {
-       bActionGroup *grp;
-       
        /* sanity checks */
        if (ELEM3(NULL, act, act->groups.first, name) || (name[0] == 0))
                return NULL;
                
        /* do string comparisons */
-       for (grp= act->groups.first; grp; grp= grp->next) {
-               if (strcmp(grp->name, name) == 0)
-                       return grp;
-       }
-       
-       /* not found */
-       return NULL;
+       return BLI_findstring(&act->groups, name, offsetof(bActionGroup, name));
 }
 
 /* *************** Pose channels *************** */
index 7c8cea12549097d148ce2f2906524ac4caf8cbb0..292d7be48d696ad34eb8f81482ef9157fa9733ba 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <stddef.h>
 #include <string.h>
 #include <fcntl.h> // for open
 
@@ -640,12 +641,8 @@ void BKE_undo_number(bContext *C, int nr)
 /* go back to the last occurance of name in stack */
 void BKE_undo_name(bContext *C, const char *name)
 {
-       UndoElem *uel;
-       
-       for(uel= undobase.last; uel; uel= uel->prev) {
-               if(strcmp(name, uel->name)==0)
-                       break;
-       }
+       UndoElem *uel= BLI_findstring(&undobase, name, offsetof(UndoElem, name));
+
        if(uel && uel->prev) {
                curundo= uel->prev;
                BKE_undo_step(C, 0);
index 9520df71b60fadf8fe116a66197ef2cf78af33d1..24dcb4c5846803a82c818862a7879a2f17969c7c 100644 (file)
@@ -25,6 +25,9 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <string.h>
+#include <stddef.h>
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_scene_types.h"
@@ -47,8 +50,6 @@
 #include "BPY_extern.h"
 #endif
 
-#include <string.h>
-
 /* struct */
 
 struct bContext {
@@ -571,13 +572,12 @@ int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListB
 static void data_dir_add(ListBase *lb, const char *member)
 {
        LinkData *link;
-
+       
        if(strcmp(member, "scene") == 0) /* exception */
                return;
 
-       for(link=lb->first; link; link=link->next)
-               if(strcmp(link->data, member) == 0)
-                       return;
+       if(BLI_findstring(lb, member, offsetof(LinkData, data)))
+               return;
        
        link= MEM_callocN(sizeof(LinkData), "LinkData");
        link->data= (void*)member;
index ccb6ebe1f1eb22c9b1e954be0bab731092edb149..91584b6236f5bfa7f59abb28270350d961119ad2 100644 (file)
@@ -176,7 +176,7 @@ void defvert_flip (MDeformVert *dvert, int *flip_map)
 }
 
 
-bDeformGroup *defgroup_find_name (Object *ob, char *name)
+bDeformGroup *defgroup_find_name (Object *ob, const char *name)
 {
        /* return a pointer to the deform group with this name
         * or return NULL otherwise.
index f4b931ec52b17a50a881c4ca12857c9cd828ffef..708403ab1f75b7a0be70df3a88ae69527781ca83 100644 (file)
@@ -50,6 +50,7 @@
 #include "BKE_animsys.h"
 #include "BKE_curve.h"
 #include "BKE_customdata.h"
+#include "BKE_deform.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
 #include "BKE_lattice.h"
@@ -1003,7 +1004,6 @@ static void do_key(int start, int end, int tot, char *poin, Key *key, KeyBlock *
 
 static float *get_weights_array(Object *ob, char *vgroup)
 {
-       bDeformGroup *curdef;
        MDeformVert *dvert= NULL;
        EditMesh *em= NULL;
        EditVert *eve;
@@ -1030,11 +1030,8 @@ static float *get_weights_array(Object *ob, char *vgroup)
        if(dvert==NULL) return NULL;
        
        /* find the group (weak loop-in-loop) */
-       for (curdef = ob->defbase.first; curdef; curdef=curdef->next, index++)
-               if (!strcmp(curdef->name, vgroup))
-                       break;
-
-       if(curdef) {
+       index= defgroup_name_index(ob, vgroup);
+       if(index >= 0) {
                float *weights;
                int i, j;
                
@@ -1539,14 +1536,8 @@ KeyBlock *key_get_keyblock(Key *key, int index)
 /* get the appropriate KeyBlock given a name to search for */
 KeyBlock *key_get_named_keyblock(Key *key, const char name[])
 {
-       KeyBlock *kb;
-       
-       if (key && name) {
-               for (kb= key->block.first; kb; kb= kb->next) {
-                       if (strcmp(name, kb->name)==0)
-                               return kb;
-               }
-       }
+       if (key && name)
+               return BLI_findstring(&key->block, name, offsetof(KeyBlock, name));
        
        return NULL;
 }
index 9dca0fa82e4ab8045a0021049f36f08c014e9f50..5af2c64da1824275a239cc0c5dc9459dc51639af 100644 (file)
@@ -734,13 +734,7 @@ void nodeGroupSocketUseFlags(bNodeTree *ngroup)
 /* finds a node based on its name */
 bNode *nodeFindNodebyName(bNodeTree *ntree, const char *name)
 {
-       bNode *node=NULL;
-       
-       for(node= ntree->nodes.first; node; node= node->next) {
-               if (strcmp(name, node->name) == 0)
-                       break;
-       }
-       return node;
+       return BLI_findstring(&ntree->nodes, name, offsetof(bNode, name));
 }
 
 /* finds a node based on given socket */
index a2ba7c69b93a5b3f9f1e93e89f07c3d8263dc31f..d8001572b4f3746c0d37236327a9bb29a472d458 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 #include <ctype.h>
 
@@ -180,14 +181,7 @@ void unique_property(bProperty *first, bProperty *prop, int force)
 
 bProperty *get_ob_property(Object *ob, char *name)
 {
-       bProperty *prop;
-       
-       prop= ob->prop.first;
-       while(prop) {
-               if( strcmp(prop->name, name)==0 ) return prop;
-               prop= prop->next;
-       }
-       return NULL;
+       return BLI_findstring(&ob->prop, name, offsetof(bProperty, name));
 }
 
 void set_ob_property(Object *ob, bProperty *propc)
index 0a58ad64e2f59dda03ea96a18dc30be5597bec24..ab236de9ac5e2bd720b8f08eefba194453c7a78a 100644 (file)
@@ -522,20 +522,12 @@ ListBase builtin_keyingsets = {NULL, NULL};
 /* Find KeyingSet type info given a name */
 KeyingSetInfo *ANIM_keyingset_info_find_named (const char name[])
 {
-       KeyingSetInfo *ksi;
-       
        /* sanity checks */
        if ((name == NULL) || (name[0] == 0))
                return NULL;
                
        /* search by comparing names */
-       for (ksi = keyingset_type_infos.first; ksi; ksi = ksi->next) {
-               if (strcmp(ksi->idname, name) == 0)
-                       return ksi;
-       }
-       
-       /* no matches found */
-       return NULL;
+       return BLI_findstring(&keyingset_type_infos, name, offsetof(KeyingSetInfo, idname));
 }
 
 /* Find builtin KeyingSet by name */
index d8374e1ed85fc083a570027ac3f3dcdbf2f2b923..a37c8a6d118d3b02a205b8c5654de6c7bf2a15b5 100644 (file)
@@ -486,13 +486,7 @@ void docenter_armature (Scene *scene, Object *ob, float cursor[3], int centermod
 /* checks if an EditBone with a matching name already, returning the matching bone if it exists */
 static EditBone *editbone_name_exists (ListBase *edbo, const char *name)
 {
-       EditBone *eBone;
-       
-       for (eBone=edbo->first; eBone; eBone=eBone->next) {
-               if (!strcmp(name, eBone->name))
-                       return eBone;
-       }
-       return NULL;
+       return BLI_findstring(edbo, name, offsetof(EditBone, name));
 }
 
 /* note: there's a unique_bone_name() too! */
@@ -4657,7 +4651,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        bArmature *arm= par->data;
        Bone **bonelist, *bone;
        bDeformGroup **dgrouplist, **dgroupflip;
-       bDeformGroup *dgroup, *curdg;
+       bDeformGroup *dgroup;
        bPoseChannel *pchan;
        Mesh *mesh;
        Mat4 *bbone = NULL;
@@ -4751,13 +4745,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
 
                        // 0 = don't strip off number extensions
                        flip_side_name(name, dgroup->name, FALSE);
-
-                       for (curdg = ob->defbase.first; curdg; curdg=curdg->next) {
-                               if (!strcmp(curdg->name, name))
-                                       break;
-                       }
-                       
-                       dgroupflip[j] = curdg;
+                       dgroupflip[j] = defgroup_find_name(ob, name);
                }
        }
 
@@ -5514,11 +5502,9 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
                        }
                        
                        if (modifiers_usesArmature(ob, arm)) { 
-                               bDeformGroup *dg;
-                               /* bone name in defgroup */
-                               for (dg=ob->defbase.first; dg; dg=dg->next) {
-                                       if (!strcmp(dg->name, oldname))
-                                          BLI_strncpy(dg->name, newname, MAXBONENAME);
+                               bDeformGroup *dg= defgroup_find_name(ob, oldname);
+                               if(dg) {
+                                       BLI_strncpy(dg->name, newname, MAXBONENAME);
                                }
                        }
                        
index f78819d1b74135741f92f4804f5a08f567ce4f6a..7cef819a795724cbf7220aef16e05d4a0e26c775 100644 (file)
@@ -55,6 +55,7 @@
 
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
+#include "BKE_deform.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
@@ -184,12 +185,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                        /* Join this object's vertex groups to the base one's */
                        for(dg=base->object->defbase.first; dg; dg=dg->next) {
                                /* See if this group exists in the object (if it doesn't, add it to the end) */
-                               for(odg=ob->defbase.first; odg; odg=odg->next) {
-                                       if(!strcmp(odg->name, dg->name)) {
-                                               break;
-                                       }
-                               }
-                               if(!odg) {
+                               if(!defgroup_find_name(ob, dg->name)) {
                                        odg = MEM_callocN(sizeof(bDeformGroup), "join deformGroup");
                                        memcpy(odg, dg, sizeof(bDeformGroup));
                                        BLI_addtail(&ob->defbase, odg);
index 5cdabcab41ab4dd338450645ee37bf2af367d2eb..377a4d15675ca2ebb22f2bc7f3aae745bf746861 100644 (file)
@@ -532,18 +532,8 @@ float ED_vgroup_vert_weight(Object *ob, bDeformGroup *dg, int vertnum)
 }
 
 void ED_vgroup_select_by_name(Object *ob, char *name)
-{
-       bDeformGroup *curdef;
-       int actdef= 1;
-       
-       for(curdef = ob->defbase.first; curdef; curdef=curdef->next, actdef++){
-               if(!strcmp(curdef->name, name)) {
-                       ob->actdef= actdef;
-                       return;
-               }
-       }
-
-       ob->actdef= 0;  // this signals on painting to create a new one, if a bone in posemode is selected */
+{      /* note: ob->actdef==0 signals on painting to create a new one, if a bone in posemode is selected */
+       ob->actdef= defgroup_name_index(ob, name) + 1;
 }
 
 /********************** Operator Implementations *********************/
index dc8cd2d7a039d98c64c9f78bd09681807388de6e..343e9c87dedd5d3baf0403f3e2f6ab6cf3e865ad 100644 (file)
@@ -122,6 +122,7 @@ EnumPropertyItem object_type_curve_items[] = {
 #include "BKE_mesh.h"
 #include "BKE_particle.h"
 #include "BKE_scene.h"
+#include "BKE_deform.h"
 
 #include "BLI_editVert.h" /* for EditMesh->mat_nr */
 
@@ -448,32 +449,19 @@ int rna_object_vgroup_name_index_length(PointerRNA *ptr, int index)
 void rna_object_vgroup_name_index_set(PointerRNA *ptr, const char *value, short *index)
 {
        Object *ob= (Object*)ptr->id.data;
-       bDeformGroup *dg;
-       int a;
-
-       for(a=1, dg=ob->defbase.first; dg; dg=dg->next, a++) {
-               if(strcmp(dg->name, value) == 0) {
-                       *index= a;
-                       return;
-               }
-       }
-
-       *index= 0;
+       *index= defgroup_name_index(ob, value) + 1;
 }
 
 void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
 {
        Object *ob= (Object*)ptr->id.data;
-       bDeformGroup *dg;
-
-       for(dg=ob->defbase.first; dg; dg=dg->next) {
-               if(strcmp(dg->name, value) == 0) {
-                       BLI_strncpy(result, value, maxlen);
-                       return;
-               }
+       bDeformGroup *dg= defgroup_find_name(ob, value);
+       if(dg) {
+               BLI_strncpy(result, value, maxlen);
+               return;
        }
 
-       BLI_strncpy(result, "", maxlen);
+       result[0]= '\0';
 }
 
 void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)