Skip to content

Commit

Permalink
perf: optimize list_insert_unique
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Feb 14, 2024
1 parent ea29226 commit 58b832d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lua/astrocore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function M.list_insert_unique(lst, ...)
if not lst then lst = {} end
assert(vim.tbl_islist(lst), "Provided table is not a list like table")
local added = {}
vim.tbl_map(function(v) added[v] = true end, lst)
for _, val in ipairs(lst) do
added[val] = true
end
for _, val in ipairs { ... } do
if not added[val] then
table.insert(lst, val)
Expand Down

0 comments on commit 58b832d

Please sign in to comment.