Skip to content

Commit

Permalink
avoid iterating the table twice for the same key
Browse files Browse the repository at this point in the history
  • Loading branch information
shreemaan-abhishek committed Jul 31, 2023
1 parent 9e57bd5 commit c6223ba
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apisix/cli/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local print = print

local _M = {}
local exported_vars
local new_keys = {}


function _M.get_exported_vars()
Expand Down Expand Up @@ -89,13 +90,18 @@ end

local function resolve_conf_var(conf)
for key, val in pairs(conf) do
-- avoid re-iterating the table for already iterated key
if new_keys[key] then
goto continue
end
-- substitute environment variables from conf keys
if type(key) == "string" then
local new_key, _, err = var_sub(key)
if err then
return nil, err
end
if new_key ~= key then
table.insert(new_keys, new_key)
conf.key = nil
conf[new_key] = val
key = new_key
Expand Down Expand Up @@ -126,6 +132,7 @@ local function resolve_conf_var(conf)

conf[key] = new_val
end
::continue::
end

return true
Expand Down

0 comments on commit c6223ba

Please sign in to comment.