perf: lazy require commands

This commit is contained in:
Folke Lemaitre 2023-10-08 20:22:01 +02:00
parent 0a07fa6cd7
commit f0cfbf9952
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 14 additions and 0 deletions

View File

@ -411,4 +411,17 @@ function M.merge(...)
return ret
end
function M.lazy_require(module)
local mod = nil
-- if already loaded, return the module
-- otherwise return a lazy module
return type(package.loaded[module]) == "table" and package.loaded[module]
or setmetatable({}, {
__index = function(_, key)
mod = mod or require(module)
return mod[key]
end,
})
end
return M

View File

@ -1,3 +1,4 @@
local require = require("lazy.core.util").lazy_require
local View = require("lazy.view")
local Manage = require("lazy.manage")
local Util = require("lazy.util")