summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/impatient.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-10-05 08:46:35 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-10-05 08:46:35 +0200
commit77cdf208765ad351e48724ed5ad57e55703eca61 (patch)
tree7f19757b255ab66895d9240a5aca77a35cef8aac /.config/nvim/lua/impatient.lua
parent4fd170aa9d55b7bcd1f0a9445c9e136b560e3220 (diff)
Add major update to LSP from lunarvim
Diffstat (limited to '.config/nvim/lua/impatient.lua')
-rw-r--r--.config/nvim/lua/impatient.lua37
1 files changed, 24 insertions, 13 deletions
diff --git a/.config/nvim/lua/impatient.lua b/.config/nvim/lua/impatient.lua
index 7d924d1..e428c7e 100644
--- a/.config/nvim/lua/impatient.lua
+++ b/.config/nvim/lua/impatient.lua
@@ -2,13 +2,12 @@
local vim = vim
local uv = vim.loop
-local impatient_start = uv.hrtime()
+local impatient_load_start = uv.hrtime()
local api = vim.api
local ffi = require "ffi"
local get_option, set_option = api.nvim_get_option, api.nvim_set_option
local get_runtime_file = api.nvim_get_runtime_file
-local home_dir = uv.os_homedir()
local impatient_dur
@@ -16,7 +15,7 @@ local M = {
cache = {},
profile = nil,
dirty = false,
- path = home_dir .. "/.local/share/nvim/cache",
+ path = nil,
log = {},
}
@@ -26,13 +25,17 @@ _G.__luacache = M
local cachepack = {}
-- using double for packing/unpacking numbers has no conversion overhead
-local c_double = ffi.typeof "double[1]"
-local sizeof_c_double = ffi.sizeof "double"
+-- 32-bit ARM causes a bus error when casting to double, so use int there
+local number_t = jit.arch ~= "arm" and "double" or "int"
+ffi.cdef("typedef " .. number_t .. " number_t;")
+
+local c_number_t = ffi.typeof "number_t[1]"
+local c_sizeof_number_t = ffi.sizeof "number_t"
local out_buf = {}
function out_buf.write_number(buf, num)
- buf[#buf + 1] = ffi.string(c_double(num), sizeof_c_double)
+ buf[#buf + 1] = ffi.string(c_number_t(num), c_sizeof_number_t)
end
function out_buf.write_string(buf, str)
@@ -50,8 +53,8 @@ function in_buf.read_number(buf)
if buf.size < buf.pos then
error "buffer access violation"
end
- local res = ffi.cast("double*", buf.ptr + buf.pos)[0]
- buf.pos = buf.pos + sizeof_c_double
+ local res = ffi.cast("number_t*", buf.ptr + buf.pos)[0]
+ buf.pos = buf.pos + c_sizeof_number_t
return res
end
@@ -270,7 +273,17 @@ function M.clear_cache()
os.remove(M.path)
end
-local function setup()
+impatient_dur = uv.hrtime() - impatient_load_start
+
+function M.setup(opts)
+ opts = opts or {}
+ M.path = opts.path or vim.fn.stdpath "cache" .. "/nvim_cache"
+
+ if opts.enable_profiling then
+ M.enable_profile()
+ end
+
+ local impatient_setup_start = uv.hrtime()
local stat = uv.fs_stat(M.path)
if stat then
log("Loading cache file %s", M.path)
@@ -339,10 +352,8 @@ local function setup()
command! LuaCacheClear lua _G.__luacache.clear_cache()
command! LuaCacheLog lua _G.__luacache.print_log()
]]
-end
-setup()
-
-impatient_dur = uv.hrtime() - impatient_start
+ impatient_dur = impatient_dur + (uv.hrtime() - impatient_setup_start)
+end
return M