aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/loader.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-31 14:16:46 +0000
committerLewis Russell <lewis6991@gmail.com>2024-10-31 15:02:08 +0000
commitf8fc6cb157555903b524422d4149132ad6ae267b (patch)
tree580703c84dadd1c58c440db9de04efe5a3cd1441 /runtime/lua/vim/loader.lua
parent03118c46abab81b12c903db88245552bad1b4861 (diff)
downloadrneovim-f8fc6cb157555903b524422d4149132ad6ae267b.tar.gz
rneovim-f8fc6cb157555903b524422d4149132ad6ae267b.tar.bz2
rneovim-f8fc6cb157555903b524422d4149132ad6ae267b.zip
perf(loader): reduce calls to Loader.cache_file
Diffstat (limited to 'runtime/lua/vim/loader.lua')
-rw-r--r--runtime/lua/vim/loader.lua16
1 files changed, 8 insertions, 8 deletions
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
index 75adee344d..526bbc6c5c 100644
--- a/runtime/lua/vim/loader.lua
+++ b/runtime/lua/vim/loader.lua
@@ -125,11 +125,10 @@ function Loader.cache_file(name)
end
--- Saves the cache entry for a given module or file
----@param name string module name or filename
+---@param cname string cache filename
---@param entry CacheEntry
---@private
-function Loader.write(name, entry)
- local cname = Loader.cache_file(name)
+function Loader.write(cname, entry)
local f = assert(uv.fs_open(cname, 'w', 438))
local header = {
Loader.VERSION,
@@ -156,11 +155,10 @@ local function readfile(path, mode)
end
--- Loads the cache entry for a given module or file
----@param name string module name or filename
+---@param cname string cache filename
---@return CacheEntry?
---@private
-function Loader.read(name)
- local cname = Loader.cache_file(name)
+function Loader.read(cname)
local data = readfile(cname, 438)
if data then
local zero = data:find('\0', 1, true)
@@ -268,7 +266,9 @@ function Loader.load(modpath, opts)
return Loader._loadfile(modpath, opts.mode, opts.env)
end
- local entry = Loader.read(modpath)
+ local cname = Loader.cache_file(modpath)
+
+ local entry = Loader.read(cname)
if entry and Loader.eq(entry.hash, hash) then
-- found in cache and up to date
chunk, err = load(entry.chunk --[[@as string]], '@' .. modpath, opts.mode, opts.env)
@@ -281,7 +281,7 @@ function Loader.load(modpath, opts)
chunk, err = Loader._loadfile(modpath, opts.mode, opts.env)
if chunk then
entry.chunk = string.dump(chunk)
- Loader.write(modpath, entry)
+ Loader.write(cname, entry)
end
return chunk, err
end