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 <alnsn@yandex.ru> (swapping)
This commit is contained in:
parent
d23662ec2e
commit
9a0904b0e0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329609
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user