From 9679251249e243fd9d08faf2240cd16c89438f11 Mon Sep 17 00:00:00 2001 From: Athozus Date: Tue, 23 May 2023 17:49:17 +0200 Subject: [PATCH] Remove unnecessary condition On (un)select all, both unselect and select start with the same block, then it is better to remove conditions that reduce performance and aren't useful. --- ui/events.lua | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/ui/events.lua b/ui/events.lua index 08e23c4..827943d 100644 --- a/ui/events.lua +++ b/ui/events.lua @@ -254,27 +254,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) elseif fields.selectall then if formname == "mail:inbox" then - if not mail.selected_idxs.inbox[name] then - mail.selected_idxs.inbox[name] = {} - end - if #mail.selected_idxs.inbox[name] >= #getInbox() then -- if selection is full - mail.selected_idxs.inbox[name] = {} - else - mail.selected_idxs.inbox[name] = {} -- reset to avoid duplicates - mail.selected_idxs.multipleselection[name] = true + mail.selected_idxs.inbox[name] = {} -- reset for select, unselect and not existing + mail.selected_idxs.multipleselection[name] = true -- enable as the button were pressed + if #mail.selected_idxs.inbox[name] < #getInbox() then -- then populate it if selection isn't full for _, msg in ipairs(getInbox()) do table.insert(mail.selected_idxs.inbox[name], msg.id) end end elseif formname == "mail:sent" then - if not mail.selected_idxs.sent[name] then - mail.selected_idxs.sent[name] = {} - end - if #mail.selected_idxs.sent[name] >= #getOutbox() then -- if selection is full - mail.selected_idxs.sent[name] = {} - else - mail.selected_idxs.sent[name] = {} -- reset to avoid duplicates - mail.selected_idxs.multipleselection[name] = true + mail.selected_idxs.sent[name] = {} -- reset for select, unselect and not existing + mail.selected_idxs.multipleselection[name] = true -- enable as the button were pressed + if #mail.selected_idxs.sent[name] < #getOutbox() then -- then populate it if selection isn't full for _, msg in ipairs(getOutbox()) do table.insert(mail.selected_idxs.sent[name], msg.id) end