From f23a6eef8ca3e8416167266cafd037a5e27a7cc6 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 16 Dec 2022 13:06:30 +0100 Subject: [PATCH] perf: prevent string.match to find plugin name from a modpath --- lua/lazy/core/plugin.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index 2859465..541e573 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -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