Skip to content

Commit

Permalink
perf(plugin): de-duplicate dependencies, keys, ft, event and cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 17, 2023
1 parent da4e8cc commit 1b2a6f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function Spec:merge(old, new)
end

if new.dependencies and old.dependencies then
vim.list_extend(new.dependencies, old.dependencies)
Util.extend(new.dependencies, old.dependencies)
end

new._.super = old
Expand Down Expand Up @@ -424,7 +424,7 @@ function M.values(plugin, prop, is_list)
end

values = type(values) == "table" and values or { values }
return is_list and vim.list_extend(ret, values) or Util.merge(ret, values)
return is_list and Util.extend(ret, values) or Util.merge(ret, values)
end

return M
17 changes: 17 additions & 0 deletions lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,23 @@ function M.lsmod(modname, fn)
end)
end

---@generic T
---@param list T[]
---@param add T[]
---@return T[]
function M.extend(list, add)
local idx = {}
for _, v in ipairs(list) do
idx[v] = v
end
for _, a in ipairs(add) do
if not idx[a] then
table.insert(list, a)
end
end
return list
end

---@alias LazyNotifyOpts {lang?:string, title?:string, level?:number}

---@param msg string|string[]
Expand Down

0 comments on commit 1b2a6f6

Please sign in to comment.