From 90dac47717b12f33d5dd738da12a337cfe4f2f14 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 1 Sep 2021 15:23:56 +1000 Subject: Cleanup: remove redundant strstr calls Rely on BLI_str_quoted_substrN to detect if the prefix exists since this function exists early there is no need to check before calling. --- source/blender/editors/animation/anim_deps.c | 11 ++--- source/blender/editors/animation/anim_filter.c | 62 +++++++++++--------------- source/blender/editors/animation/keyframing.c | 17 +++---- 3 files changed, 39 insertions(+), 51 deletions(-) (limited to 'source/blender/editors/animation') diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c index 42fdb714127..2cc0f6ad288 100644 --- a/source/blender/editors/animation/anim_deps.c +++ b/source/blender/editors/animation/anim_deps.c @@ -207,19 +207,14 @@ static void animchan_sync_fcurve_scene(bAnimListElem *ale) Scene *scene = (Scene *)owner_id; FCurve *fcu = (FCurve *)ale->data; - /* only affect if F-Curve involves sequence_editor.sequences */ - if (!strstr(fcu->rna_path, "sequences_all")) { - return; - } - - Editing *ed = SEQ_editing_get(scene, false); - - /* get strip name, and check if this strip is selected */ + /* Only affect if F-Curve involves sequence_editor.sequences. */ char *seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["); if (seq_name == NULL) { return; } + /* Check if this strip is selected. */ + Editing *ed = SEQ_editing_get(scene, false); Sequence *seq = SEQ_get_sequence_by_name(ed->seqbasep, seq_name, false); MEM_freeN(seq_name); diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index 020518b5813..2252fc4fcbc 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -1061,20 +1061,16 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id if (GS(owner_id->name) == ID_OB) { Object *ob = (Object *)owner_id; + char *bone_name; - /* only consider if F-Curve involves pose.bones */ - if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) { - - /* get bone-name, and check if this bone is selected */ - bPoseChannel *pchan = NULL; - char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); - if (bone_name) { - pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - MEM_freeN(bone_name); - } + /* Only consider if F-Curve involves `pose.bones`. */ + if (fcu->rna_path && (bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["))) { + /* Get bone-name, and check if this bone is selected. */ + bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name); + MEM_freeN(bone_name); /* check whether to continue or skip */ - if ((pchan) && (pchan->bone)) { + if (pchan && pchan->bone) { /* If only visible channels, * skip if bone not visible unless user wants channels from hidden data too. */ if (skip_hidden) { @@ -1101,22 +1097,19 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id } else if (GS(owner_id->name) == ID_SCE) { Scene *scene = (Scene *)owner_id; + char *seq_name; - /* only consider if F-Curve involves sequence_editor.sequences */ - if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) { - Editing *ed = SEQ_editing_get(scene, false); + /* Only consider if F-Curve involves `sequence_editor.sequences`. */ + if (fcu->rna_path && (seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["))) { + /* Get strip name, and check if this strip is selected. */ Sequence *seq = NULL; - + Editing *ed = SEQ_editing_get(scene, false); if (ed) { - /* get strip name, and check if this strip is selected */ - char *seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["); - if (seq_name) { - seq = SEQ_get_sequence_by_name(ed->seqbasep, seq_name, false); - MEM_freeN(seq_name); - } + seq = SEQ_get_sequence_by_name(ed->seqbasep, seq_name, false); } + MEM_freeN(seq_name); - /* can only add this F-Curve if it is selected */ + /* Can only add this F-Curve if it is selected. */ if (ads->filterflag & ADS_FILTER_ONLYSEL) { if ((seq == NULL) || (seq->flag & SELECT) == 0) { return true; @@ -1126,22 +1119,21 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id } else if (GS(owner_id->name) == ID_NT) { bNodeTree *ntree = (bNodeTree *)owner_id; + char *node_name; - /* check for selected nodes */ - if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) { + /* Check for selected nodes. */ + if (fcu->rna_path && (node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes["))) { bNode *node = NULL; + /* Get strip name, and check if this strip is selected. */ + node = nodeFindNodebyName(ntree, node_name); + MEM_freeN(node_name); - /* get strip name, and check if this strip is selected */ - char *node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes["); - if (node_name) { - node = nodeFindNodebyName(ntree, node_name); - MEM_freeN(node_name); - } - - /* can only add this F-Curve if it is selected */ - if (ads->filterflag & ADS_FILTER_ONLYSEL) { - if ((node) && (node->flag & NODE_SELECT) == 0) { - return true; + /* Can only add this F-Curve if it is selected. */ + if (node) { + if (ads->filterflag & ADS_FILTER_ONLYSEL) { + if ((node->flag & NODE_SELECT) == 0) { + return true; + } } } } diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 0a499232ba9..292d665caca 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -2216,9 +2216,8 @@ static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op)) /* in pose mode, only delete the F-Curve if it belongs to a selected bone */ if (ob->mode & OB_MODE_POSE) { - if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones[")) { - - /* get bone-name, and check if this bone is selected */ + if (fcu->rna_path) { + /* Get bone-name, and check if this bone is selected. */ char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); if (bone_name) { bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name); @@ -2320,16 +2319,18 @@ static int delete_key_v3d_without_keying_set(bContext *C, wmOperator *op) * NOTE: This is only done in pose mode. * In object mode, we're dealing with the entire object. */ - if ((ob->mode & OB_MODE_POSE) && strstr(fcu->rna_path, "pose.bones[\"")) { + if (ob->mode & OB_MODE_POSE) { bPoseChannel *pchan = NULL; - /* get bone-name, and check if this bone is selected */ + /* Get bone-name, and check if this bone is selected. */ char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); - if (bone_name) { - pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - MEM_freeN(bone_name); + if (bone_name == NULL) { + continue; } + pchan = BKE_pose_channel_find_name(ob->pose, bone_name); + MEM_freeN(bone_name); + /* skip if bone is not selected */ if ((pchan) && (pchan->bone)) { /* bones are only selected/editable if visible... */ -- cgit v1.2.3