aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/pack.lua
diff options
context:
space:
mode:
authorEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2025-08-22 12:53:13 +0300
committerEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2025-08-22 13:00:30 +0300
commit92e7d5eaf2a9f0950c2c5023f536d4500342f461 (patch)
tree8af74adae367ef32de828d4024bbe313c70f1167 /runtime/lua/vim/pack.lua
parentd73cfefed5e45fec91a422cd87054611ff711b30 (diff)
downloadrneovim-92e7d5eaf2a9f0950c2c5023f536d4500342f461.tar.gz
rneovim-92e7d5eaf2a9f0950c2c5023f536d4500342f461.tar.bz2
rneovim-92e7d5eaf2a9f0950c2c5023f536d4500342f461.zip
perf(pack): reduce number of 'opt/' directory computations
Diffstat (limited to 'runtime/lua/vim/pack.lua')
-rw-r--r--runtime/lua/vim/pack.lua15
1 files changed, 10 insertions, 5 deletions
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
index 3b6d9c92ae..ea3007731d 100644
--- a/runtime/lua/vim/pack.lua
+++ b/runtime/lua/vim/pack.lua
@@ -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