diff options
-rw-r--r-- | source/blender/blenkernel/BKE_deform.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/action.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/blender.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/context.c | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 19 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/property.c | 10 | ||||
-rw-r--r-- | source/blender/editors/animation/keyingsets.c | 10 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 26 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 8 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 14 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 26 |
13 files changed, 38 insertions, 118 deletions
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 702cb100e18..53f474aa972 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -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); diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 41ff3fed8a5..90a3a6ce664 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -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 *************** */ diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 7c8cea12549..292d7be48d6 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -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); diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 9520df71b60..24dcb4c5846 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -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; diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index ccb6ebe1f1e..91584b6236f 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -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. diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index f4b931ec52b..708403ab1f7 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -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; } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 9dca0fa82e4..5af2c64da18 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -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 */ diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index a2ba7c69b93..d8001572b4f 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -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) diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 0a58ad64e2f..ab236de9ac5 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -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 */ diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index d8374e1ed85..a37c8a6d118 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -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); } } diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index f78819d1b74..7cef819a795 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -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); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 5cdabcab41a..377a4d15675 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -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 *********************/ diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index dc8cd2d7a03..343e9c87ded 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -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) |