svn commit: r329609 - head/stand/lua
Kyle Evans
kevans at FreeBSD.org
Mon Feb 19 22:29:17 UTC 2018
Author: kevans
Date: Mon Feb 19 22:29:16 2018
New Revision: 329609
URL: https://svnweb.freebsd.org/changeset/base/329609
Log:
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 at yandex.ru> (swapping)
Modified:
head/stand/lua/menu.lua
Modified: head/stand/lua/menu.lua
==============================================================================
--- head/stand/lua/menu.lua Mon Feb 19 22:22:35 2018 (r329608)
+++ head/stand/lua/menu.lua Mon Feb 19 22:29:16 2018 (r329609)
@@ -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,
More information about the svn-src-all
mailing list