[Bf-blender-cvs] [7a62574338c] master: Cleanup: Reduce variable scope

Hans Goudey noreply at git.blender.org
Thu Jan 28 20:52:45 CET 2021


Commit: 7a62574338c3ddc8c83fcbf7f38cef4ec54bc5b8
Author: Hans Goudey
Date:   Thu Jan 28 13:52:39 2021 -0600
Branches: master
https://developer.blender.org/rB7a62574338c3ddc8c83fcbf7f38cef4ec54bc5b8

Cleanup: Reduce variable scope

Also some minimal white space changes

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

M	source/blender/editors/space_outliner/outliner_tree.c

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

diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c
index acfeccca175..7df6115cb06 100644
--- a/source/blender/editors/space_outliner/outliner_tree.c
+++ b/source/blender/editors/space_outliner/outliner_tree.c
@@ -167,8 +167,6 @@ static void outliner_storage_cleanup(SpaceOutliner *space_outliner)
 static void check_persistent(
     SpaceOutliner *space_outliner, TreeElement *te, ID *id, short type, short nr)
 {
-  TreeStoreElem *tselem;
-
   if (space_outliner->treestore == NULL) {
     /* if treestore was not created in readfile.c, create it here */
     space_outliner->treestore = BLI_mempool_create(
@@ -181,7 +179,8 @@ static void check_persistent(
 
   /* find any unused tree element in treestore and mark it as used
    * (note that there may be multiple unused elements in case of linked objects) */
-  tselem = BKE_outliner_treehash_lookup_unused(space_outliner->runtime->treehash, type, nr, id);
+  TreeStoreElem *tselem = BKE_outliner_treehash_lookup_unused(
+      space_outliner->runtime->treehash, type, nr, id);
   if (tselem) {
     te->store_elem = tselem;
     tselem->used = 1;
@@ -204,8 +203,7 @@ static void check_persistent(
 
 void outliner_free_tree(ListBase *tree)
 {
-  for (TreeElement *element = tree->first, *element_next; element; element = element_next) {
-    element_next = element->next;
+  LISTBASE_FOREACH_MUTABLE (TreeElement *, element, tree) {
     outliner_free_tree_element(element, tree);
   }
 }
@@ -271,8 +269,8 @@ static void outliner_add_bone(SpaceOutliner *space_outliner,
   te->name = curBone->name;
   te->directdata = curBone;
 
-  for (curBone = curBone->childbase.first; curBone; curBone = curBone->next) {
-    outliner_add_bone(space_outliner, &te->subtree, id, curBone, te, a);
+  LISTBASE_FOREACH (Bone *, child_bone, &curBone->childbase) {
+    outliner_add_bone(space_outliner, &te->subtree, id, child_bone, te, a);
   }
 }
 
@@ -381,35 +379,30 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
 
   if (ob->pose) {
     bArmature *arm = ob->data;
-    bPoseChannel *pchan;
     TreeElement *tenla = outliner_add_element(
         space_outliner, &te->subtree, ob, te, TSE_POSE_BASE, 0);
-
     tenla->name = IFACE_("Pose");
 
     /* channels undefined in editmode, but we want the 'tenla' pose icon itself */
     if ((arm->edbo == NULL) && (ob->mode & OB_MODE_POSE)) {
-      TreeElement *ten;
-      int a = 0, const_index = 1000; /* ensure unique id for bone constraints */
-
-      for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next, a++) {
-        ten = outliner_add_element(
+      int const_index = 1000; /* ensure unique id for bone constraints */
+      int a;
+      LISTBASE_FOREACH_INDEX (bPoseChannel *, pchan, &ob->pose->chanbase, a) {
+        TreeElement *ten = outliner_add_element(
             space_outliner, &tenla->subtree, ob, tenla, TSE_POSE_CHANNEL, a);
         ten->name = pchan->name;
         ten->directdata = pchan;
         pchan->temp = (void *)ten;
 
-        if (pchan->constraints.first) {
+        if (!BLI_listbase_is_empty(&pchan->constraints)) {
           /* Object *target; */
-          bConstraint *con;
-          TreeElement *ten1;
           TreeElement *tenla1 = outliner_add_element(
               space_outliner, &ten->subtree, ob, ten, TSE_CONSTRAINT_BASE, 0);
+          tenla1->name = IFACE_("Constraints");
           /* char *str; */
 
-          tenla1->name = IFACE_("Constraints");
-          for (con = pchan->constraints.first; con; con = con->next, const_index++) {
-            ten1 = outliner_add_element(
+          LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) {
+            TreeElement *ten1 = outliner_add_element(
                 space_outliner, &tenla1->subtree, ob, tenla1, TSE_CONSTRAINT, const_index);
 #if 0 /* disabled as it needs to be reworked for recoded constraints system */
             target = get_constraint_target(con, &str);
@@ -427,15 +420,16 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
             ten1->directdata = con;
             /* possible add all other types links? */
           }
+          const_index++;
         }
       }
       /* make hierarchy */
-      ten = tenla->subtree.first;
+      TreeElement *ten = tenla->subtree.first;
       while (ten) {
         TreeElement *nten = ten->next, *par;
         tselem = TREESTORE(ten);
         if (tselem->type == TSE_POSE_CHANNEL) {
-          pchan = (bPoseChannel *)ten->directdata;
+          bPoseChannel *pchan = (bPoseChannel *)ten->directdata;
           if (pchan->parent) {
             BLI_remlink(&tenla->subtree, ten);
             par = (TreeElement *)pchan->parent->temp;
@@ -448,17 +442,15 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
     }
 
     /* Pose Groups */
-    if (ob->pose->agroups.first) {
-      bActionGroup *agrp;
+    if (!BLI_listbase_is_empty(&ob->pose->agroups)) {
       TreeElement *ten_bonegrp = outliner_add_element(
           space_outliner, &te->subtree, ob, te, TSE_POSEGRP_BASE, 0);
-      int a = 0;
-
       ten_bonegrp->name = IFACE_("Bone Groups");
-      for (agrp = ob->pose->agroups.first; agrp; agrp = agrp->next, a++) {
-        TreeElement *ten;
-        ten = outliner_add_element(
-            space_outliner, &ten_bonegrp->subtree, ob, ten_bonegrp, TSE_POSEGRP, a);
+
+      int index;
+      LISTBASE_FOREACH_INDEX (bActionGroup *, agrp, &ob->pose->agroups, index) {
+        TreeElement *ten = outliner_add_element(
+            space_outliner, &ten_bonegrp->subtree, ob, ten_bonegrp, TSE_POSEGRP, index);
         ten->name = agrp->name;
         ten->directdata = agrp;
       }
@@ -469,18 +461,15 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
     outliner_add_element(space_outliner, &te->subtree, ob->mat[a], te, 0, a);
   }
 
-  if (ob->constraints.first) {
-    /* Object *target; */
-    bConstraint *con;
-    TreeElement *ten;
+  if (!BLI_listbase_is_empty(&ob->constraints)) {
     TreeElement *tenla = outliner_add_element(
         space_outliner, &te->subtree, ob, te, TSE_CONSTRAINT_BASE, 0);
-    /* char *str; */
-    int a;
-
     tenla->name = IFACE_("Constraints");
-    for (con = ob->constraints.first, a = 0; con; con = con->next, a++) {
-      ten = outliner_add_element(space_outliner, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, a);
+
+    int index;
+    LISTBASE_FOREACH_INDEX (bConstraint *, con, &ob->constraints, index) {
+      TreeElement *ten = outliner_add_element(
+          space_outliner, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, index);
 #if 0 /* disabled due to constraints system targets recode... code here needs review */
       target = get_constraint_target(con, &str);
       if (str && str[0]) {
@@ -499,14 +488,13 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
     }
   }
 
-  if (ob->modifiers.first) {
-    ModifierData *md;
+  if (!BLI_listbase_is_empty(&ob->modifiers)) {
     TreeElement *ten_mod = outliner_add_element(
         space_outliner, &te->subtree, ob, te, TSE_MODIFIER_BASE, 0);
-    int index;
-
     ten_mod->name = IFACE_("Modifiers");
-    for (index = 0, md = ob->modifiers.first; md; index++, md = md->next) {
+
+    int index;
+    LISTBASE_FOREACH_INDEX (ModifierData *, md, &ob->modifiers, index) {
       TreeElement *ten = outliner_add_element(
           space_outliner, &ten_mod->subtree, ob, ten_mod, TSE_MODIFIER, index);
       ten->name = md->name;
@@ -559,8 +547,8 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
   if (!BLI_listbase_is_empty(&ob->greasepencil_modifiers)) {
     TreeElement *ten_mod = outliner_add_element(
         space_outliner, &te->subtree, ob, te, TSE_MODIFIER_BASE, 0);
-
     ten_mod->name = IFACE_("Modifiers");
+
     int index;
     LISTBASE_FOREACH_INDEX (GpencilModifierData *, md, &ob->greasepencil_modifiers, index) {
       TreeElement *ten = outliner_add_element(
@@ -599,8 +587,8 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
   if (!BLI_listbase_is_empty(&ob->shader_fx)) {
     TreeElement *ten_fx = outliner_add_element(
         space_outliner, &te->subtree, ob, te, TSE_GPENCIL_EFFECT_BASE, 0);
-
     ten_fx->name = IFACE_("Effects");
+
     int index;
     LISTBASE_FOREACH_INDEX (ShaderFxData *, fx, &ob->shader_fx, index) {
       TreeElement *ten = outliner_add_element(
@@ -620,16 +608,15 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner,
   }
 
   /* vertex groups */
-  if (ob->defbase.first) {
-    bDeformGroup *defgroup;
-    TreeElement *ten;
+  if (!BLI_listbase_is_empty(&ob->defbase)) {
     TreeElement *tenla = outliner_add_element(
         space_outliner, &te->subtree, ob, te, TSE_DEFGROUP_BASE, 0);
-    int a;
-
     tenla->name = IFACE_("Vertex Groups");
-    for (defgroup = ob->defbase.first, a = 0; defgroup; defgroup = defgroup->next, a++) {
-      ten = outliner_add_element(space_outliner, &tenla->subtree, ob, tenla, TSE_DEFGROUP, a);
+
+    int index;
+    LISTBASE_FOREACH_INDEX (bDeformGroup *, defgroup, &ob->defbase, index) {
+      TreeElement *ten = outliner_add_element(
+          space_outliner, &tenla->subtree, ob, tenla, TSE_DEFGROUP, index);
       ten->name = defgroup->name;
       ten->directdata = defgroup;
     }
@@ -694,14 +681,13 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner,
     }
     case ID_ME: {
       Mesh *me = (Mesh *)id;
-      int a;
 
       if (outliner_animdata_test(me->adt)) {
         outliner_add_element(space_outliner, &te->subtree, me, te, TSE_ANIM_DATA, 0);
       }
 
       outliner_add_element(space_outliner, &te->subtree, me->key, te, 0, 0);
-      for (a = 0; a < me->totcol; a++) {
+      for (int a = 0; a < me->totcol; a++) {
         outliner_add_element(space_outliner, &te->subtree, me->mat[a], te, 0, a);
       }
       /* could do tfaces with image links, but the images are not grouped nicely.
@@ -710,33 +696,30 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner,
     }
     case ID_CU: {
       Curve *cu = (Curve *)id;
-      int a;
 
       if (outliner_animdata_te

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list