perf(plugin): de-duplicate dependencies, keys, ft, event and cmd

This commit is contained in:
Folke Lemaitre 2023-01-17 14:00:33 +01:00
parent da4e8cc245
commit 1b2a6f631c
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 19 additions and 2 deletions

View File

@ -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
@ -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

View File

@ -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[]