From 418e5b824d100c672cd2437782064a86b4ad7709 Mon Sep 17 00:00:00 2001 From: kevans Date: Mon, 19 Feb 2018 22:29:16 +0000 Subject: [PATCH] stand/lua: Cache swapped menu, and don't create locals for swapping Building the swapped welcome menu (first two items swapped) is kind of a sluggish, because it requires a full (recrusive) shallow copy of the welcome menu. Cache the result of that and re-use it later, instead of building it everytime. While here, don't create temporary locals just for swapping. The following is just as good: x, y = y, x; Reported by: Alexander Nasonov (swapping) --- stand/lua/menu.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/stand/lua/menu.lua b/stand/lua/menu.lua index 17d5a8940e32..5f8260969110 100644 --- a/stand/lua/menu.lua +++ b/stand/lua/menu.lua @@ -138,17 +138,22 @@ menu.welcome = { local menu_entries = menu.welcome.all_entries; -- Swap the first two menu items on single user boot if (core.isSingleUserBoot()) then + -- We'll cache the swapped menu, for performance + if (menu.welcome.swapped_menu ~= nil) then + return menu.welcome.swapped_menu; + end -- Shallow copy the table menu_entries = core.shallowCopyTable(menu_entries); - local multiuser = menu_entries[1]; - local singleuser = menu_entries[2]; + -- Swap the first two menu entries + menu_entries[1], menu_entries[2] = menu_entries[2], + menu_entries[1]; - multiuser.name = multiuser.alternate_name; - singleuser.name = singleuser.alternate_name; - - menu_entries[2] = multiuser; - menu_entries[1] = singleuser; + -- Then set their names to their alternate names + menu_entries[1].name, menu_entries[2].name = + menu_entries[1].alternate_name, + menu_entries[2].alternate_name; + menu.welcome.swapped_menu = menu_entries; end return menu_entries; end,