mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
perf(pack): reduce number of 'opt/' directory computations
This commit is contained in:
@@ -270,10 +270,11 @@ end
|
||||
--- @field info vim.pack.PlugInfo Gathered information about plugin.
|
||||
|
||||
--- @param spec string|vim.pack.Spec
|
||||
--- @param plug_dir string?
|
||||
--- @return vim.pack.Plug
|
||||
local function new_plug(spec)
|
||||
local function new_plug(spec, plug_dir)
|
||||
local spec_resolved = normalize_spec(spec)
|
||||
local path = vim.fs.joinpath(get_plug_dir(), spec_resolved.name)
|
||||
local path = vim.fs.joinpath(plug_dir or get_plug_dir(), spec_resolved.name)
|
||||
local info = { err = '', installed = uv.fs_stat(path) ~= nil }
|
||||
return { spec = spec_resolved, path = path, info = info }
|
||||
end
|
||||
@@ -324,6 +325,7 @@ end
|
||||
--- @return vim.pack.Plug[]
|
||||
local function plug_list_from_names(names)
|
||||
local all_plugins = M.get()
|
||||
local plug_dir = get_plug_dir()
|
||||
local plugs = {} --- @type vim.pack.Plug[]
|
||||
local used_names = {} --- @type table<string,boolean>
|
||||
-- Preserve plugin order; might be important during checkout or event trigger
|
||||
@@ -334,7 +336,7 @@ local function plug_list_from_names(names)
|
||||
-- TODO(echasnovski): Consider changing this if/when there is lockfile.
|
||||
--- @cast names string[]
|
||||
if (not names and p_data.active) or vim.tbl_contains(names or {}, p_data.spec.name) then
|
||||
plugs[#plugs + 1] = new_plug(p_data.spec)
|
||||
plugs[#plugs + 1] = new_plug(p_data.spec, plug_dir)
|
||||
used_names[p_data.spec.name] = true
|
||||
end
|
||||
end
|
||||
@@ -712,8 +714,11 @@ function M.add(specs, opts)
|
||||
opts = vim.tbl_extend('force', { load = vim.v.vim_did_enter == 1, confirm = true }, opts or {})
|
||||
vim.validate('opts', opts, 'table')
|
||||
|
||||
--- @type vim.pack.Plug[]
|
||||
local plugs = vim.tbl_map(new_plug, specs)
|
||||
local plug_dir = get_plug_dir()
|
||||
local plugs = {} --- @type vim.pack.Plug[]
|
||||
for i = 1, #specs do
|
||||
plugs[i] = new_plug(specs[i], plug_dir)
|
||||
end
|
||||
plugs = normalize_plugs(plugs)
|
||||
|
||||
-- Install
|
||||
|
Reference in New Issue
Block a user