perf: prevent string.match to find plugin name from a modpath

This commit is contained in:
Folke Lemaitre 2022-12-16 13:06:30 +01:00
parent ecf03a6892
commit f23a6eef8c
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 9 additions and 2 deletions

View File

@ -258,8 +258,15 @@ end
-- Finds the plugin that has this path
---@param path string
function M.find(path)
local name = path:match("/([^/]+)/lua") or path:match("/([^/]+)/?$")
return name and Config.plugins[name] or nil
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 nil
end
end
end
return M