Skip to content

Commit

Permalink
perf: prevent string.match to find plugin name from a modpath
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 16, 2022
1 parent ecf03a6 commit f23a6ee
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f23a6ee

Please sign in to comment.