From 53dfcf9d6f1c42e54194e1cb2c6d453e8a003eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 1 Feb 2022 18:37:41 +0000 Subject: [PATCH] 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 --- Firmware/mesh_bed_calibration.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Firmware/mesh_bed_calibration.h b/Firmware/mesh_bed_calibration.h index c539d4b59..02b97cc2d 100644 --- a/Firmware/mesh_bed_calibration.h +++ b/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; - } - if (tmpy < Y_MIN_POS) { - tmpy = Y_MIN_POS; - clamped = true; - } - if (tmpx > X_MAX_POS) { + } else if (tmpx > X_MAX_POS) { tmpx = X_MAX_POS; clamped = true; } - if (tmpy > Y_MAX_POS) { + + if (tmpy < Y_MIN_POS) { + tmpy = Y_MIN_POS; + clamped = true; + } else if (tmpy > Y_MAX_POS) { tmpy = Y_MAX_POS; clamped = true; }