mirror of https://github.com/folke/lazy.nvim.git
feat(cache): drop dependency on ffi
This commit is contained in:
parent
da295017e4
commit
810acc1e86
|
@ -7,7 +7,6 @@ if type(package.loaded["vim.cache"]) == "table" then
|
||||||
return package.loaded["vim.cache"]
|
return package.loaded["vim.cache"]
|
||||||
end
|
end
|
||||||
|
|
||||||
local ffi = require("ffi")
|
|
||||||
local uv = vim.loop
|
local uv = vim.loop
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
@ -20,7 +19,7 @@ local M = {}
|
||||||
---@field patterns? string[] Paterns to use (defaults to `{"/init.lua", ".lua"}`)
|
---@field patterns? string[] Paterns to use (defaults to `{"/init.lua", ".lua"}`)
|
||||||
---@field paths? string[] Extra paths to search for modname
|
---@field paths? string[] Extra paths to search for modname
|
||||||
|
|
||||||
M.VERSION = 2
|
M.VERSION = 3
|
||||||
M.path = vim.fn.stdpath("cache") .. "/luac"
|
M.path = vim.fn.stdpath("cache") .. "/luac"
|
||||||
M.enabled = false
|
M.enabled = false
|
||||||
---@type table<string, {total:number, time:number, [string]:number?}?>
|
---@type table<string, {total:number, time:number, [string]:number?}?>
|
||||||
|
@ -114,7 +113,7 @@ function Cache.write(name, entry)
|
||||||
entry.hash.mtime.sec,
|
entry.hash.mtime.sec,
|
||||||
entry.hash.mtime.nsec,
|
entry.hash.mtime.nsec,
|
||||||
}
|
}
|
||||||
uv.fs_write(f, ffi.string(ffi.new("const uint32_t[4]", header), 16))
|
uv.fs_write(f, table.concat(header, ",") .. "\0")
|
||||||
uv.fs_write(f, entry.chunk)
|
uv.fs_write(f, entry.chunk)
|
||||||
uv.fs_close(f)
|
uv.fs_close(f)
|
||||||
end
|
end
|
||||||
|
@ -132,15 +131,17 @@ function Cache.read(name)
|
||||||
local data = uv.fs_read(f, hash.size, 0) --[[@as string]]
|
local data = uv.fs_read(f, hash.size, 0) --[[@as string]]
|
||||||
uv.fs_close(f)
|
uv.fs_close(f)
|
||||||
|
|
||||||
|
local zero = data:find("\0", 1, true)
|
||||||
|
|
||||||
---@type integer[]|{[0]:integer}
|
---@type integer[]|{[0]:integer}
|
||||||
local header = ffi.cast("uint32_t*", ffi.new("const char[16]", data:sub(1, 16)))
|
local header = vim.split(data:sub(1, zero - 1), ",")
|
||||||
if header[0] ~= M.VERSION then
|
if tonumber(header[1]) ~= M.VERSION then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
M.track("read", start)
|
M._track("read", start)
|
||||||
return {
|
return {
|
||||||
hash = { size = header[1], mtime = { sec = header[2], nsec = header[3] } },
|
hash = { size = tonumber(header[2]), mtime = { sec = tonumber(header[3]), nsec = tonumber(header[4]) } },
|
||||||
chunk = data:sub(16 + 1),
|
chunk = data:sub(zero + 1),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
M._track("read", start)
|
M._track("read", start)
|
||||||
|
|
Loading…
Reference in New Issue