[Bf-blender-cvs] [63916f5941b] master: Cleanup: reduce variable scope

Jacques Lucke noreply at git.blender.org
Wed Sep 9 18:41:45 CEST 2020


Commit: 63916f5941b443dfc8566682bb75374e5abd553f
Author: Jacques Lucke
Date:   Wed Sep 9 18:41:07 2020 +0200
Branches: master
https://developer.blender.org/rB63916f5941b443dfc8566682bb75374e5abd553f

Cleanup: reduce variable scope

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

M	source/blender/editors/animation/drivers.c
M	source/blender/editors/animation/fmodifier_ui.c
M	source/blender/editors/animation/keyframes_edit.c
M	source/blender/editors/animation/keyframes_general.c
M	source/blender/editors/animation/keyframing.c
M	source/blender/editors/armature/armature_select.c
M	source/blender/editors/armature/armature_skinning.c
M	source/blender/editors/armature/armature_utils.c
M	source/blender/editors/armature/meshlaplacian.c
M	source/blender/editors/armature/pose_edit.c
M	source/blender/editors/armature/pose_group.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/curve/editcurve_select.c
M	source/blender/editors/gpencil/annotate_paint.c
M	source/blender/editors/gpencil/gpencil_convert.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_merge.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_sculpt_paint.c
M	source/blender/editors/gpencil/gpencil_vertex_ops.c
M	source/blender/editors/interface/interface_align.c
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_region_tooltip.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/interface/view2d_ops.c
M	source/blender/editors/lattice/editlattice_select.c
M	source/blender/editors/mask/mask_add.c
M	source/blender/editors/mask/mask_ops.c
M	source/blender/editors/mask/mask_select.c
M	source/blender/editors/mesh/editface.c
M	source/blender/editors/mesh/editmesh_knife.c
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/object/object_bake_api.c
M	source/blender/editors/object/object_data_transfer.c
M	source/blender/editors/object/object_facemap_ops.c
M	source/blender/editors/object/object_transform.c
M	source/blender/editors/object/object_vgroup.c
M	source/blender/editors/object/object_warp.c
M	source/blender/editors/physics/particle_edit_undo.c
M	source/blender/editors/physics/particle_object.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/sculpt_paint/paint_curve.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
M	source/blender/editors/sculpt_paint/paint_vertex_color_utils.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/editors/space_clip/clip_buttons.c
M	source/blender/editors/space_clip/clip_draw.c
M	source/blender/editors/space_clip/clip_editor.c
M	source/blender/editors/space_clip/clip_ops.c
M	source/blender/editors/space_clip/clip_utils.c
M	source/blender/editors/space_clip/tracking_ops.c
M	source/blender/editors/space_clip/tracking_select.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/fsmenu.c
M	source/blender/editors/space_graph/graph_draw.c
M	source/blender/editors/space_node/node_add.c
M	source/blender/editors/space_node/node_relationships.c
M	source/blender/editors/space_node/node_templates.c
M	source/blender/editors/space_sequencer/sequencer_add.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/editors/space_sequencer/sequencer_scopes.c
M	source/blender/editors/space_sequencer/sequencer_select.c
M	source/blender/editors/space_text/text_ops.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/transform/transform_constraints.c
M	source/blender/editors/transform/transform_convert_mask.c

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

diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index 3b15cd794d8..4d5ff33d5cf 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -355,9 +355,8 @@ int ANIM_add_driver_with_target(ReportList *reports,
       int src_len = (RNA_property_array_check(prop)) ? RNA_property_array_length(&ptr2, prop2) : 1;
 
       int len = MIN2(dst_len, src_len);
-      int i;
 
-      for (i = 0; i < len; i++) {
+      for (int i = 0; i < len; i++) {
         done_tot += add_driver_with_target(reports,
                                            dst_id,
                                            dst_path,
@@ -378,9 +377,8 @@ int ANIM_add_driver_with_target(ReportList *reports,
     case CREATEDRIVER_MAPPING_1_N: /* 1-N - Specified target index for all */
     default: {
       int len = (RNA_property_array_check(prop)) ? RNA_property_array_length(&ptr, prop) : 1;
-      int i;
 
-      for (i = 0; i < len; i++) {
+      for (int i = 0; i < len; i++) {
         done_tot += add_driver_with_target(reports,
                                            dst_id,
                                            dst_path,
diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c
index 9d54be61171..a8fb0be4fbf 100644
--- a/source/blender/editors/animation/fmodifier_ui.c
+++ b/source/blender/editors/animation/fmodifier_ui.c
@@ -177,7 +177,6 @@ static void draw_modifier__generator(uiLayout *layout,
       const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
       float *cp = NULL;
       char xval[32];
-      uint i;
       int maxXWidth;
 
       /* draw polynomial order selector */
@@ -221,7 +220,7 @@ static void draw_modifier__generator(uiLayout *layout,
       UI_block_func_set(block, deg_update, fcurve_owner_id, NULL);
 
       cp = data->coefficients;
-      for (i = 0; (i < data->arraysize) && (cp); i++, cp++) {
+      for (uint i = 0; (i < data->arraysize) && (cp); i++, cp++) {
         /* To align with first line... */
         if (i) {
           uiDefBut(block,
@@ -319,7 +318,6 @@ static void draw_modifier__generator(uiLayout *layout,
     case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* Factorized polynomial expression */
     {
       float *cp = NULL;
-      uint i;
 
       /* draw polynomial order selector */
       row = uiLayoutRow(layout, false);
@@ -351,7 +349,7 @@ static void draw_modifier__generator(uiLayout *layout,
       UI_block_func_set(block, deg_update, fcurve_owner_id, NULL);
 
       cp = data->coefficients;
-      for (i = 0; (i < data->poly_order) && (cp); i++, cp += 2) {
+      for (uint i = 0; (i < data->poly_order) && (cp); i++, cp += 2) {
         /* To align with first line */
         if (i) {
           uiDefBut(block,
diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c
index ef86b132a60..de2525ee150 100644
--- a/source/blender/editors/animation/keyframes_edit.c
+++ b/source/blender/editors/animation/keyframes_edit.c
@@ -943,11 +943,8 @@ KeyframeEditFunc ANIM_editkeyframes_snap(short mode)
 
 static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center)
 {
-  float diff;
-  int i;
-
-  for (i = 0; i < 3; i++) {
-    diff = (center - bezt->vec[i][0]);
+  for (int i = 0; i < 3; i++) {
+    float diff = (center - bezt->vec[i][0]);
     bezt->vec[i][0] = (center + diff);
   }
   swap_v3_v3(bezt->vec[0], bezt->vec[2]);
@@ -958,11 +955,8 @@ static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center)
 
 static void mirror_bezier_yaxis_ex(BezTriple *bezt, const float center)
 {
-  float diff;
-  int i;
-
-  for (i = 0; i < 3; i++) {
-    diff = (center - bezt->vec[i][1]);
+  for (int i = 0; i < 3; i++) {
+    float diff = (center - bezt->vec[i][1]);
     bezt->vec[i][1] = (center + diff);
   }
 }
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c
index 64065d6d633..ea032446fc6 100644
--- a/source/blender/editors/animation/keyframes_general.c
+++ b/source/blender/editors/animation/keyframes_general.c
@@ -108,7 +108,6 @@ void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc)
 /* Delete selected keyframes in given F-Curve */
 bool delete_fcurve_keys(FCurve *fcu)
 {
-  int i;
   bool changed = false;
 
   if (fcu->bezt == NULL) { /* ignore baked curves */
@@ -116,7 +115,7 @@ bool delete_fcurve_keys(FCurve *fcu)
   }
 
   /* Delete selected BezTriples */
-  for (i = 0; i < fcu->totvert; i++) {
+  for (int i = 0; i < fcu->totvert; i++) {
     if (fcu->bezt[i].f2 & SELECT) {
       memmove(&fcu->bezt[i], &fcu->bezt[i + 1], sizeof(BezTriple) * (fcu->totvert - i - 1));
       fcu->totvert--;
@@ -148,19 +147,16 @@ void clear_fcurve_keys(FCurve *fcu)
 /* duplicate selected keyframes for the given F-Curve */
 void duplicate_fcurve_keys(FCurve *fcu)
 {
-  BezTriple *newbezt;
-  int i;
-
   /* this can only work when there is an F-Curve, and also when there are some BezTriples */
   if (ELEM(NULL, fcu, fcu->bezt)) {
     return;
   }
 
-  for (i = 0; i < fcu->totvert; i++) {
+  for (int i = 0; i < fcu->totvert; i++) {
     /* If a key is selected */
     if (fcu->bezt[i].f2 & SELECT) {
       /* Expand the list */
-      newbezt = MEM_callocN(sizeof(BezTriple) * (fcu->totvert + 1), "beztriple");
+      BezTriple *newbezt = MEM_callocN(sizeof(BezTriple) * (fcu->totvert + 1), "beztriple");
 
       memcpy(newbezt, fcu->bezt, sizeof(BezTriple) * (i + 1));
       memcpy(newbezt + i + 1, fcu->bezt + i, sizeof(BezTriple));
@@ -489,16 +485,15 @@ typedef struct tSmooth_Bezt {
 // TODO: introduce scaling factor for weighting falloff
 void smooth_fcurve(FCurve *fcu)
 {
-  BezTriple *bezt;
-  int i, x, totSel = 0;
+  int totSel = 0;
 
   if (fcu->bezt == NULL) {
     return;
   }
 
   /* first loop through - count how many verts are selected */
-  bezt = fcu->bezt;
-  for (i = 0; i < fcu->totvert; i++, bezt++) {
+  BezTriple *bezt = fcu->bezt;
+  for (int i = 0; i < fcu->totvert; i++, bezt++) {
     if (BEZT_ISSEL_ANY(bezt)) {
       totSel++;
     }
@@ -513,7 +508,7 @@ void smooth_fcurve(FCurve *fcu)
 
     /* populate tarray with data of selected points */
     bezt = fcu->bezt;
-    for (i = 0, x = 0; (i < fcu->totvert) && (x < totSel); i++, bezt++) {
+    for (int i = 0, x = 0; (i < fcu->totvert) && (x < totSel); i++, bezt++) {
       if (BEZT_ISSEL_ANY(bezt)) {
         /* tsb simply needs pointer to vec, and index */
         tsb->h1 = &bezt->vec[0][1];
@@ -539,7 +534,7 @@ void smooth_fcurve(FCurve *fcu)
 
     /* round 1: calculate smoothing deltas and new values */
     tsb = tarray;
-    for (i = 0; i < totSel; i++, tsb++) {
+    for (int i = 0; i < totSel; i++, tsb++) {
       /* Don't touch end points (otherwise, curves slowly explode,
        * as we don't have enough data there). */
       if (ELEM(i, 0, (totSel - 1)) == 0) {
@@ -564,7 +559,7 @@ void smooth_fcurve(FCurve *fcu)
 
     /* round 2: apply new values */
     tsb = tarray;
-    for (i = 0; i < totSel; i++, tsb++) {
+    for (int i = 0; i < totSel; i++, tsb++) {
       /* don't touch end points, as their values weren't touched above */
       if (ELEM(i, 0, (totSel - 1)) == 0) {
         /* y2 takes the average of the 2 points */
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 66d4882cf9d..fb4c0ae0758 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -618,22 +618,19 @@ enum {
  */
 static short new_key_needed(FCurve *fcu, float cFrame, float nValue)
 {
-  BezTriple *bezt = NULL, *prev = NULL;
-  int totCount, i;
-  float valA = 0.0f, valB = 0.0f;
-
   /* safety checking */
   if (fcu == NULL) {
     return KEYNEEDED_JUSTADD;
   }
-  totCount = fcu->totvert;
+  int totCount = fcu->totvert;
   if (totCount == 0) {
     return KEYNEEDED_JUSTADD;
   }
 
   /* loop through checking if any are the same */
-  bezt = fcu->bezt;
-  for (i = 0; i < totCount; i++) {
+  BezTriple *bezt = fcu->bezt;
+  BezTriple *prev = NULL;
+  for (int i = 0; i < totCount; i++) {
     float prevPosi = 0.0f, prevVal = 0.0f;
     float beztPosi = 0.0f, beztVal = 0.0f;
 
@@ -712,8 +709,8 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue)
    *    keyframe is not equal to last keyframe.
    */
   bezt = (fcu->bezt + (fcu->totvert - 1));
-  valA = bezt->vec[1][1];
-
+  float valA = bezt->vec[1][1];
+  float valB;
   if (prev) {
     valB = prev->vec[1][1];
   }
diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c
index 7fba855ffdb..4c5efb304c9 100644
--- a/source/blender/editors/armature/armature_select.c
+++ b/source/blender/editors/armature/armature_select.c
@@ -177,11 +177,10 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode
   void *firstunSel = NULL, *firstSel = NULL, *data;
   Base *firstunSel_base = NULL, *firstSel_base = NULL;
   uint hitresult;
-  short i;
   bool takeNext = false;
   int minsel = 0xffffffff, minunsel = 0xffffffff;
 
-  for (i = 0; i < hits; i++) {
+  for (short i = 0; i < hits; i++) {
     hitresult = buffer[3 + (i * 4)];
 
     if (hitresult & BONESEL_ANY) { /* to avoid including objects in selection */
diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c
index ea9b0eb92b9..aa742d4b7ba 100644
--- a/source/blender/editors/armature/armature_skinning.c
+++ b/source/blender/editors/armature/armature_skinning.c
@@ -212,10 +212,6 @@ static void envelope_bone_weighting(Object *ob,
 {
   /* Create vertex group weights from envelopes */
 
-  Bone *bone;
-  bDeformGroup *dgroup;
-  float distance;
-  int i, iflip, j;
   bool use_topology = (mesh->editflag & ME_EDIT_MIRROR_TOPO) != 0;
   bool use_mask = false;
 
@@ -225,30 +221,30 @@ static void envelope_bone_weighting(Object *ob,
   }
 
   /* for each vertex in the mesh */
-  for (i = 0; i < mesh->totvert; i++) {
+  for (int i = 0; i < mesh->totvert; i++) {
 
     if (use_mask && !(mesh->mvert[i].flag & SELECT)) {
       continue;
     }
 
-    iflip 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list