From e31102e8c9de467fa21e3f73c74c6a782648b2a5 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 16 Feb 2022 18:05:24 -0300 Subject: no need for a make_shallow_copy utility function --- src/luarocks/core/cfg.lua | 7 ++++++- src/luarocks/core/util.lua | 13 ------------- src/luarocks/util.lua | 8 +++++--- 3 files changed, 11 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 264c88b6..f0e5aa93 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -77,11 +77,16 @@ local load_config_file do -- Create global environment for the config files; local function env_for_config_file(cfg, platforms) + local platforms_copy = {} + for k,v in pairs(platforms) do + platforms_copy[k] = v + end + local e e = { home = cfg.home, lua_version = cfg.lua_version, - platforms = util.make_shallow_copy(platforms), + platforms = platforms_copy, processor = cfg.target_cpu, -- remains for compat reasons target_cpu = cfg.target_cpu, -- replaces `processor` os_getenv = os.getenv, diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 67a10b42..26e78369 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua @@ -28,19 +28,6 @@ function util.popen_read(cmd, spec) return out or "" end ---- Create a new shallow copy of a table: a new table with --- the same keys and values. Keys point to the same objects as --- the original table (ie, does not copy recursively). --- @param tbl table: the input table --- @return table: a new table with the same contents. -function util.make_shallow_copy(tbl) - local copy = {} - for k,v in pairs(tbl) do - copy[k] = v - end - return copy -end - --- -- Formats tables with cycles recursively to any depth. -- References to other tables are shown as values. diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index bb474ff0..fa3a628e 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -90,14 +90,16 @@ local var_format_pattern = "%$%((%a[%a%d_]+)%)" -- needed variables. -- @param msg string: the warning message to display. function util.warn_if_not_used(var_defs, needed_set, msg) - needed_set = core.make_shallow_copy(needed_set) + local seen = {} for _, val in pairs(var_defs) do for used in val:gmatch(var_format_pattern) do - needed_set[used] = nil + seen[used] = true end end for var, _ in pairs(needed_set) do - util.warning(msg:format(var)) + if not seen[var] then + util.warning(msg:format(var)) + end end end -- cgit v1.2.3-55-g6feb