mirror of https://github.com/folke/lazy.nvim.git
refactor(cache): Cache.track => Cache._track
This commit is contained in:
parent
0b7596f609
commit
da295017e4
|
@ -42,7 +42,7 @@ local Cache = {
|
||||||
|
|
||||||
--- Tracks the time spent in a function
|
--- Tracks the time spent in a function
|
||||||
---@private
|
---@private
|
||||||
function M.track(stat, start)
|
function M._track(stat, start)
|
||||||
M.stats[stat] = M.stats[stat] or { total = 0, time = 0 }
|
M.stats[stat] = M.stats[stat] or { total = 0, time = 0 }
|
||||||
M.stats[stat].total = M.stats[stat].total + 1
|
M.stats[stat].total = M.stats[stat].total + 1
|
||||||
M.stats[stat].time = M.stats[stat].time + uv.hrtime() - start
|
M.stats[stat].time = M.stats[stat].time + uv.hrtime() - start
|
||||||
|
@ -71,7 +71,7 @@ end
|
||||||
function Cache.get_rtp()
|
function Cache.get_rtp()
|
||||||
local start = uv.hrtime()
|
local start = uv.hrtime()
|
||||||
if vim.in_fast_event() then
|
if vim.in_fast_event() then
|
||||||
M.track("get_rtp", start)
|
M._track("get_rtp", start)
|
||||||
return (Cache._rtp or {}), false
|
return (Cache._rtp or {}), false
|
||||||
end
|
end
|
||||||
local updated = false
|
local updated = false
|
||||||
|
@ -88,7 +88,7 @@ function Cache.get_rtp()
|
||||||
updated = true
|
updated = true
|
||||||
Cache._rtp_key = key
|
Cache._rtp_key = key
|
||||||
end
|
end
|
||||||
M.track("get_rtp", start)
|
M._track("get_rtp", start)
|
||||||
return Cache._rtp, updated
|
return Cache._rtp, updated
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ function Cache.read(name)
|
||||||
chunk = data:sub(16 + 1),
|
chunk = data:sub(16 + 1),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
M.track("read", start)
|
M._track("read", start)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- The `package.loaders` loader for lua files using the cache.
|
--- The `package.loaders` loader for lua files using the cache.
|
||||||
|
@ -155,10 +155,10 @@ function Cache.loader(modname)
|
||||||
local modpath, hash = M.find(modname)
|
local modpath, hash = M.find(modname)
|
||||||
if modpath then
|
if modpath then
|
||||||
local chunk, err = M.load(modpath, { hash = hash })
|
local chunk, err = M.load(modpath, { hash = hash })
|
||||||
M.track("loader", start)
|
M._track("loader", start)
|
||||||
return chunk or error(err)
|
return chunk or error(err)
|
||||||
end
|
end
|
||||||
M.track("loader", start)
|
M._track("loader", start)
|
||||||
return "\ncache_loader: module " .. modname .. " not found"
|
return "\ncache_loader: module " .. modname .. " not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -179,10 +179,10 @@ function Cache.loader_lib(modname)
|
||||||
local dash = modname:find("-", 1, true)
|
local dash = modname:find("-", 1, true)
|
||||||
local funcname = dash and modname:sub(dash + 1) or modname
|
local funcname = dash and modname:sub(dash + 1) or modname
|
||||||
local chunk, err = package.loadlib(modpath, "luaopen_" .. funcname:gsub("%.", "_"))
|
local chunk, err = package.loadlib(modpath, "luaopen_" .. funcname:gsub("%.", "_"))
|
||||||
M.track("loader_lib", start)
|
M._track("loader_lib", start)
|
||||||
return chunk or error(err)
|
return chunk or error(err)
|
||||||
end
|
end
|
||||||
M.track("loader_lib", start)
|
M._track("loader_lib", start)
|
||||||
return "\ncache_loader_lib: module " .. modname .. " not found"
|
return "\ncache_loader_lib: module " .. modname .. " not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ function Cache.loadfile(filename, mode, env)
|
||||||
filename = Cache.normalize(filename)
|
filename = Cache.normalize(filename)
|
||||||
mode = nil -- ignore mode, since we byte-compile the lua source files
|
mode = nil -- ignore mode, since we byte-compile the lua source files
|
||||||
local chunk, err = M.load(filename, { mode = mode, env = env })
|
local chunk, err = M.load(filename, { mode = mode, env = env })
|
||||||
M.track("loadfile", start)
|
M._track("loadfile", start)
|
||||||
return chunk, err
|
return chunk, err
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ function M.load(modpath, opts)
|
||||||
if not hash then
|
if not hash then
|
||||||
-- trigger correct error
|
-- trigger correct error
|
||||||
chunk, err = Cache._loadfile(modpath, opts.mode, opts.env)
|
chunk, err = Cache._loadfile(modpath, opts.mode, opts.env)
|
||||||
M.track("load", start)
|
M._track("load", start)
|
||||||
return chunk, err
|
return chunk, err
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ function M.load(modpath, opts)
|
||||||
-- selene: allow(incorrect_standard_library_use)
|
-- selene: allow(incorrect_standard_library_use)
|
||||||
chunk, err = load(entry.chunk --[[@as string]], "@" .. modpath, opts.mode, opts.env)
|
chunk, err = load(entry.chunk --[[@as string]], "@" .. modpath, opts.mode, opts.env)
|
||||||
if not (err and err:find("cannot load incompatible bytecode", 1, true)) then
|
if not (err and err:find("cannot load incompatible bytecode", 1, true)) then
|
||||||
M.track("load", start)
|
M._track("load", start)
|
||||||
return chunk, err
|
return chunk, err
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -252,7 +252,7 @@ function M.load(modpath, opts)
|
||||||
entry.chunk = string.dump(chunk)
|
entry.chunk = string.dump(chunk)
|
||||||
Cache.write(modpath, entry)
|
Cache.write(modpath, entry)
|
||||||
end
|
end
|
||||||
M.track("load", start)
|
M._track("load", start)
|
||||||
return chunk, err
|
return chunk, err
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ function M.find(modname, opts)
|
||||||
modpath, hash = _find(opts.paths)
|
modpath, hash = _find(opts.paths)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.track("find", start)
|
M._track("find", start)
|
||||||
if modpath then
|
if modpath then
|
||||||
return modpath, hash
|
return modpath, hash
|
||||||
end
|
end
|
||||||
|
@ -422,7 +422,7 @@ function M.lsmod(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
M.track("lsmod", start)
|
M._track("lsmod", start)
|
||||||
end
|
end
|
||||||
return Cache._indexed[path]
|
return Cache._indexed[path]
|
||||||
end
|
end
|
||||||
|
@ -434,8 +434,8 @@ function M.profile_loaders()
|
||||||
package.loaders[l] = function(modname)
|
package.loaders[l] = function(modname)
|
||||||
local start = vim.loop.hrtime()
|
local start = vim.loop.hrtime()
|
||||||
local ret = loader(modname)
|
local ret = loader(modname)
|
||||||
M.track("loader " .. l .. ": " .. loc, start)
|
M._track("loader " .. l .. ": " .. loc, start)
|
||||||
M.track("loader_all", start)
|
M._track("loader_all", start)
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue