mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
Compare commits
2 Commits
db2d00185d
...
9e2d109bfa
Author | SHA1 | Date | |
---|---|---|---|
|
9e2d109bfa | ||
|
329a6d82cb |
@ -120,12 +120,22 @@ local function cache_filename(name)
|
|||||||
return ret:sub(-4) == '.lua' and (ret .. 'c') or (ret .. '.luac')
|
return ret:sub(-4) == '.lua' and (ret .. 'c') or (ret .. '.luac')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local writing = {} --- @type table<string,function>
|
||||||
|
|
||||||
--- Saves the cache entry for a given module or file
|
--- Saves the cache entry for a given module or file
|
||||||
--- @param cname string cache filename
|
--- @param cname string cache filename
|
||||||
--- @param hash vim.loader.CacheHash
|
--- @param hash vim.loader.CacheHash
|
||||||
--- @param chunk function
|
--- @param chunk function
|
||||||
local function write_cachefile(cname, hash, chunk)
|
local function write_cachefile(cname, hash, chunk)
|
||||||
local f = assert(uv.fs_open(cname, 'w', 438))
|
if writing[cname] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
writing[cname] = chunk
|
||||||
|
uv.fs_open(cname, 'w', 438, function(err, f)
|
||||||
|
if err then
|
||||||
|
error(err)
|
||||||
|
end
|
||||||
local header = {
|
local header = {
|
||||||
VERSION,
|
VERSION,
|
||||||
hash.size,
|
hash.size,
|
||||||
@ -135,6 +145,8 @@ local function write_cachefile(cname, hash, chunk)
|
|||||||
uv.fs_write(f, table.concat(header, ',') .. '\0')
|
uv.fs_write(f, table.concat(header, ',') .. '\0')
|
||||||
uv.fs_write(f, string.dump(chunk))
|
uv.fs_write(f, string.dump(chunk))
|
||||||
uv.fs_close(f)
|
uv.fs_close(f)
|
||||||
|
writing[cname] = nil
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param path string
|
--- @param path string
|
||||||
@ -255,6 +267,10 @@ local function loadfile_cached(filename, mode, env)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if writing[cname] then
|
||||||
|
return writing[cname]
|
||||||
|
end
|
||||||
|
|
||||||
local chunk, err = _loadfile(modpath, mode, env)
|
local chunk, err = _loadfile(modpath, mode, env)
|
||||||
if chunk and stat then
|
if chunk and stat then
|
||||||
write_cachefile(cname, stat, chunk)
|
write_cachefile(cname, stat, chunk)
|
||||||
|
Loading…
Reference in New Issue
Block a user