[Bf-blender-cvs] [a9d1b3d7e3e] master: Cleanup: replace in-line swapping with SWAP macro

Campbell Barton noreply at git.blender.org
Tue Apr 26 06:27:06 CEST 2022


Commit: a9d1b3d7e3e9fa52c811d9807c8a26aa1c64b327
Author: Campbell Barton
Date:   Tue Apr 26 14:24:44 2022 +1000
Branches: master
https://developer.blender.org/rBa9d1b3d7e3e9fa52c811d9807c8a26aa1c64b327

Cleanup: replace in-line swapping with SWAP macro

Also use bool array for true/false values.

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

M	source/blender/editors/object/object_vgroup.c

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

diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index a58ffa4e0a6..1ad722d4fdc 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -1344,13 +1344,13 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
   float *dists = MEM_mallocN(sizeof(float) * totweight, "distance");
 
   /* track if up or down moved it closer for each bone */
-  int *upDown = MEM_callocN(sizeof(int) * totweight, "upDownTracker");
+  bool *upDown = MEM_callocN(sizeof(bool) * totweight, "upDownTracker");
 
   int *dwIndices = MEM_callocN(sizeof(int) * totweight, "dwIndexTracker");
   float distToStart;
   int bestIndex = 0;
   bool wasChange;
-  char wasUp;
+  bool wasUp;
   int lastIndex = -1;
   float originalDistToBe = distToBe;
   do {
@@ -1410,13 +1410,13 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
         }
         else {
           if (fabsf(dist - distToBe) < fabsf(dists[i] - distToBe)) {
-            upDown[i] = 0;
+            upDown[i] = false;
             changes[i][0] = vc;
             changes[i][1] = hc;
             dists[i] = dist;
           }
           else {
-            upDown[i] = 1;
+            upDown[i] = true;
           }
           if (fabsf(dists[i] - distToBe) > fabsf(distToStart - distToBe)) {
             changes[i][0] = 0;
@@ -1428,8 +1428,6 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
     }
     /* sort the changes by the vertical change */
     for (k = 0; k < totweight; k++) {
-      float tf;
-      int ti;
       bestIndex = k;
       for (i = k + 1; i < totweight; i++) {
         dist = dists[i];
@@ -1440,25 +1438,10 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
       }
       /* switch with k */
       if (bestIndex != k) {
-        ti = upDown[k];
-        upDown[k] = upDown[bestIndex];
-        upDown[bestIndex] = ti;
-
-        ti = dwIndices[k];
-        dwIndices[k] = dwIndices[bestIndex];
-        dwIndices[bestIndex] = ti;
-
-        tf = changes[k][0];
-        changes[k][0] = changes[bestIndex][0];
-        changes[bestIndex][0] = tf;
-
-        tf = changes[k][1];
-        changes[k][1] = changes[bestIndex][1];
-        changes[bestIndex][1] = tf;
-
-        tf = dists[k];
-        dists[k] = dists[bestIndex];
-        dists[bestIndex] = tf;
+        SWAP(bool, upDown[k], upDown[bestIndex]);
+        SWAP(int, dwIndices[k], dwIndices[bestIndex]);
+        swap_v2_v2(changes[k], changes[bestIndex]);
+        SWAP(float, dists[k], dists[bestIndex]);
       }
     }
     bestIndex = -1;



More information about the Bf-blender-cvs mailing list