[Bf-blender-cvs] [90dac47717b] master: Cleanup: remove redundant strstr calls

Campbell Barton noreply at git.blender.org
Wed Sep 1 07:33:42 CEST 2021


Commit: 90dac47717b12f33d5dd738da12a337cfe4f2f14
Author: Campbell Barton
Date:   Wed Sep 1 15:23:56 2021 +1000
Branches: master
https://developer.blender.org/rB90dac47717b12f33d5dd738da12a337cfe4f2f14

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.

===================================================================

M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/editors/animation/anim_deps.c
M	source/blender/editors/animation/anim_filter.c
M	source/blender/editors/animation/keyframing.c
M	source/blender/editors/armature/pose_select.c
M	source/blender/editors/transform/transform_convert_armature.c

===================================================================

diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 5decc7a1792..fb6cd5871f4 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -349,7 +349,7 @@ int BKE_fcurves_filter(ListBase *dst, ListBase *src, const char *dataPrefix, con
   /* Search each F-Curve one by one. */
   for (fcu = src->first; fcu; fcu = fcu->next) {
     /* Check if quoted string matches the path. */
-    if (fcu->rna_path == NULL || !strstr(fcu->rna_path, dataPrefix)) {
+    if (fcu->rna_path == NULL) {
       continue;
     }
 
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... */
diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c
index 1dbb859fd6c..4db8569a7d2 100644
--- a/source/blender/editors/armature/pose_select.c
+++ b/source/blender/editors/armature/pose_select.c
@@ -1106,20 +1106,18 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex
     for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
       /* only items related to this object will be relevant */
       if ((ksp->id == &ob->id) && (ksp->rna_path != NULL)) {
-        if (strstr(ksp->rna_path, "bones")) {
-          char *boneName = BLI_str_quoted_substrN(ksp->rna_path, "bones[");
-
-          if (boneName) {
-            bPoseChannel *pchan = BKE_pose_channel_find_name(pose, boneName);
-            MEM_freeN(boneName);
-
-            if (pchan) {
-              /* select if bone is visible and can be affected */
-              if (PBONE_SELECTABLE(arm, pchan->bone)) {
-                pchan->bone->flag |= BONE_SELECTED;
-                changed = true;
-              }
-            }
+        char *boneName = BLI_str_quoted_substrN(ksp->rna_path, "bones[");
+        if (boneName == NULL) {
+          continue;
+        }
+        bPoseChannel *pchan = BKE_pose_channel_find_name(pose, boneName);
+        MEM_freeN(boneName);
+
+        if (pchan) {
+          /* select if bone is visible and can be affected */
+          if (PBONE_SELECTABLE(arm, pchan->bone)) {
+            pchan->bone->flag |= BONE_SELECTED;
+            changed = true;
           }
         }
       }
diff --git a/source/blender/editors/transform/transform_convert_armature.c b/source/blender/editors/transform/transform_convert_armature.c
index 5627a910ab4..98e00c20170 100644
--- a/source/blender/editors/transform/transform_convert_armature.c
+++ b/source/blender/editors/transform/transform_convert_armature.c
@@ -145,31 +145,29 @@ static void autokeyframe_pose(
       if (act) {
         for (fcu = act->curves.first; fcu; fcu = fcu->next) {
           /* only insert keyframes for this F-Curve if it affects the current bone */
-          if (strstr(fcu->rna_path, "bones") == NULL) {
+          char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
+          if (pchanName == NULL) {
             continue;
           }
-          char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
 


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list