Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Feb 2018 22:29:16 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329609 - head/stand/lua
Message-ID:  <201802192229.w1JMTG9C082624@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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@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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802192229.w1JMTG9C082624>