From 4ce3fa53a18dc3ffd8f906dc91b99d5f4b4c799c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Fri, 21 Apr 2023 17:42:55 +0000 Subject: [PATCH] Optimise M0/M1 code size Replace two bool variables with one. It's not obvious but (!hasP && !hasS) is equal to !(hasP || hasS) Note: expiration_time_set = hasP || hasS Truth table: |--------------------------------------------------| | hasP| hasS| (!hasP && !hasS)| !(hasP || hasS) | |------|-----|--------------------|-----------------| | 0 | 0 | 1 | 1 | | 0 | 1 | 0 | 0 | | 1 | 0 | 0 | 0 | | 1 | 1 | 0 | 0 | |--------------------------------------------------| Change in memory: Flash: -36 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8a8dc0a51..6b6c662f1 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5221,18 +5221,13 @@ void process_commands() case 1: { const char *src = strchr_pointer + 2; codenum = 0; - bool hasP = false, hasS = false; - if (code_seen('P')) { - codenum = code_value_long(); // milliseconds to wait - hasP = codenum > 0; - } - if (code_seen('S')) { - codenum = code_value_long() * 1000; // seconds to wait - hasS = codenum > 0; - } + if (code_seen('P')) codenum = code_value_long(); // milliseconds to wait + if (code_seen('S')) codenum = code_value_long() * 1000; // seconds to wait + bool expiration_time_set = bool(codenum); + while (*src == ' ') ++src; custom_message_type = CustomMsg::M0Wait; - if (!hasP && !hasS && *src != '\0') { + if (!expiration_time_set && *src != '\0') { lcd_setstatus(src); } else { // farmers want to abuse a bug from the previous firmware releases @@ -5247,7 +5242,7 @@ void process_commands() st_synchronize(); menu_set_block(MENU_BLOCK_STATUS_SCREEN_M0); previous_millis_cmd.start(); - if (codenum > 0 ) { + if (expiration_time_set) { codenum += _millis(); // keep track of when we started waiting KEEPALIVE_STATE(PAUSED_FOR_USER); while(_millis() < codenum && !lcd_clicked()) {