perf: minimize meta rebuild when loading specs

This commit is contained in:
Folke Lemaitre 2024-06-24 21:56:43 +02:00
parent 972baa615b
commit 1446f6cfbb
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
4 changed files with 67 additions and 13 deletions

View file

@ -362,17 +362,24 @@ end
-- Finds the plugin that has this path
---@param path string
function M.find(path)
---@param opts? {fast?:boolean}
function M.find(path, opts)
if not Config.spec then
return
end
opts = opts or {}
local lua = path:find("/lua/", 1, true)
if lua then
local name = path:sub(1, lua - 1)
local slash = name:reverse():find("/", 1, true)
if slash then
name = name:sub(#name - slash + 2)
return name and Config.plugins[name] or Config.spec.plugins[name] or nil
if name then
if opts.fast then
return Config.spec.meta.plugins[name]
end
return Config.spec.plugins[name]
end
end
end
end