From cabc44194ae2eaed3ac117d6ad6bd241ddf9bcd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 14 May 2023 10:27:02 +0000 Subject: [PATCH] optimisation: menu_item == menu_line is always true The if statement is checked in lcd_sdcard_menu() so checking it again these functions is redundant since it's always going to be true. Tested on MK3S+ Change in memory: Flash: -22 bytes SRAM: 0 bytes --- Firmware/ultralcd.cpp | 46 +++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index cf353d4ac8..3a2a33c2b7 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -277,40 +277,34 @@ static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* lon static void menu_item_sddir(const char* str_fn, char* str_fnl) { - if (menu_item == menu_line) + if (lcd_draw_update) { - if (lcd_draw_update) - { - lcd_implementation_drawmenu_sddirectory(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl); - } - if (menu_clicked && (lcd_encoder == menu_item)) - { - lcd_update_enabled = false; - menu_action_sddirectory(str_fn); - lcd_update_enabled = true; - menu_item_ret(); - return; - } + lcd_implementation_drawmenu_sddirectory(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl); + } + if (menu_clicked && (lcd_encoder == menu_item)) + { + lcd_update_enabled = false; + menu_action_sddirectory(str_fn); + lcd_update_enabled = true; + menu_item_ret(); + return; } menu_item++; } static void menu_item_sdfile(const char* str_fn, char* str_fnl) { - if (menu_item == menu_line) + if (lcd_draw_update) { - if (lcd_draw_update) - { - lcd_implementation_drawmenu_sdfile(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl); - } - if (menu_clicked && (lcd_encoder == menu_item)) - { - lcd_update_enabled = false; - menu_action_sdfile(str_fn); - lcd_update_enabled = true; - menu_item_ret(); - return; - } + lcd_implementation_drawmenu_sdfile(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl); + } + if (menu_clicked && (lcd_encoder == menu_item)) + { + lcd_update_enabled = false; + menu_action_sdfile(str_fn); + lcd_update_enabled = true; + menu_item_ret(); + return; } menu_item++; }