Skip to content

Commit f23a6ee

Browse files
committed
perf: prevent string.match to find plugin name from a modpath
1 parent ecf03a6 commit f23a6ee

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lua/lazy/core/plugin.lua

+9-2
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,15 @@ end
258258
-- Finds the plugin that has this path
259259
---@param path string
260260
function M.find(path)
261-
local name = path:match("/([^/]+)/lua") or path:match("/([^/]+)/?$")
262-
return name and Config.plugins[name] or nil
261+
local lua = path:find("/lua", 1, true)
262+
if lua then
263+
local name = path:sub(1, lua - 1)
264+
local slash = name:reverse():find("/", 1, true)
265+
if slash then
266+
name = name:sub(#name - slash + 2)
267+
return name and Config.plugins[name] or nil
268+
end
269+
end
263270
end
264271

265272
return M

0 commit comments

Comments
 (0)