Browse Source

Optimise if-statments in world2machine_clamp

Only one of the statements can be true: tmpx < X_MIN_POS or tmpx > X_MAX_POS.
So we can be a little bit smarter here and skip the second if statement if the first was true.

This saves 6 bytes of flash memory and potential some clock cycles
Guðni Már Gilbert 2 years ago
parent
commit
53dfcf9d6f
1 changed files with 5 additions and 6 deletions
  1. 5 6
      Firmware/mesh_bed_calibration.h

+ 5 - 6
Firmware/mesh_bed_calibration.h

@@ -129,16 +129,15 @@ inline bool world2machine_clamp(float &x, float &y)
     if (tmpx < X_MIN_POS) {
         tmpx = X_MIN_POS;
         clamped = true;
+    } else if (tmpx > X_MAX_POS) {
+        tmpx = X_MAX_POS;
+        clamped = true;
     }
+    
     if (tmpy < Y_MIN_POS) {
         tmpy = Y_MIN_POS;
         clamped = true;
-    }
-    if (tmpx > X_MAX_POS) {
-        tmpx = X_MAX_POS;
-        clamped = true;
-    }
-    if (tmpy > Y_MAX_POS) {
+    } else if (tmpy > Y_MAX_POS) {
         tmpy = Y_MAX_POS;
         clamped = true;
     }