Compare commits

..

2 Commits

Author SHA1 Message Date
vanaigr
35cea0b28d refactor: cleanup 2024-12-18 12:10:50 -06:00
vanaigr
b037af3f2c refactor: use function in exec_lua 2024-12-18 12:10:21 -06:00
5 changed files with 61 additions and 74 deletions

View File

@ -1483,16 +1483,13 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
} }
// Call it here since we need to invalidate the line pointer anyway. // Call it here since we need to invalidate the line pointer anyway.
bool added_decor = false; decor_providers_invoke_line(wp, lnum - 1, &has_decor);
decor_providers_invoke_line(wp, lnum - 1, &added_decor);
has_decor |= added_decor;
decor_provider_end_col = invoke_range_next(wp, lnum, col, rem_vcols + 1, &has_decor); decor_provider_end_col = invoke_range_next(wp, lnum, col, rem_vcols + 1, &has_decor);
line = ml_get_buf(wp->w_buffer, lnum); line = ml_get_buf(wp->w_buffer, lnum);
ptr = line + col; ptr = line + col;
} }
if (has_decor) { if (has_decor) {
extra_check = true; extra_check = true;
} }
@ -3039,18 +3036,16 @@ static int invoke_range_next(win_T *wp, int lnum, colnr_T begin_col, colnr_T col
int const line_len = ml_get_buf_len(wp->w_buffer, lnum); int const line_len = ml_get_buf_len(wp->w_buffer, lnum);
col_off = MAX(col_off, 1); col_off = MAX(col_off, 1);
bool added_decor = false;
colnr_T new_col; colnr_T new_col;
if (col_off <= line_len - begin_col) { if (col_off <= line_len - begin_col) {
int end_col = begin_col + col_off; int end_col = begin_col + col_off;
end_col += mb_off_next(line, line + end_col); end_col += mb_off_next(line, line + end_col);
decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum - 1, end_col, &added_decor); decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum - 1, end_col, has_decor);
new_col = end_col; new_col = end_col;
} else { } else {
decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum, 0, &added_decor); decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum, 0, has_decor);
new_col = INT_MAX; new_col = INT_MAX;
} }
*has_decor |= added_decor;
return new_col; return new_col;
} }

View File

@ -1291,23 +1291,22 @@ static inline bool set_uint32(lua_State *L, int idx, char const *name, uint32_t
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_NONNULL_ALL FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_NONNULL_ALL
{ {
lua_getfield(L, idx, name); lua_getfield(L, idx, name);
if (lua_isnil(L, -1)) {
if (!lua_isnil(L, -1)) { lua_pop(L, 1);
int64_t value = lua_tointeger(L, -1); return false;
if (value < 0U) {
*res = 0U;
return true;
} else if (value > UINT32_MAX) {
*res = UINT32_MAX;
return true;
} else {
*res = (uint32_t)value;
return true;
}
} }
int64_t value = lua_tointeger(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
return false; if (value < 0U) {
*res = 0U;
} else if (value > UINT32_MAX) {
*res = UINT32_MAX;
} else {
*res = (uint32_t)value;
}
return true;
} }
int tslua_push_querycursor(lua_State *L) int tslua_push_querycursor(lua_State *L)

View File

@ -8,7 +8,7 @@ describe('decor perf', function()
it('can handle long lines', function() it('can handle long lines', function()
Screen.new(100, 101) Screen.new(100, 101)
local result = exec_lua [==[ local result = exec_lua(function()
local ephemeral_pattern = { local ephemeral_pattern = {
{ 0, 4, 'Comment', 11 }, { 0, 4, 'Comment', 11 },
{ 0, 3, 'Keyword', 12 }, { 0, 3, 'Keyword', 12 },
@ -61,7 +61,7 @@ describe('decor perf', function()
return true return true
end, end,
on_line = function() on_line = function()
add_pattern(ephemeral_pattern, true) add_pattern(ephemeral_pattern, true)
end, end,
}) })
@ -69,16 +69,16 @@ describe('decor perf', function()
local total = {} local total = {}
local provider = {} local provider = {}
for i = 1, 100 do for _ = 1, 100 do
local tic = vim.uv.hrtime() local tic = vim.uv.hrtime()
vim.cmd'redraw!' vim.cmd 'redraw!'
local toc = vim.uv.hrtime() local toc = vim.uv.hrtime()
table.insert(total, toc - tic) table.insert(total, toc - tic)
table.insert(provider, pe - ps) table.insert(provider, pe - ps)
end end
return { total, provider } return { total, provider }
]==] end)
local total, provider = unpack(result) local total, provider = unpack(result)
table.sort(total) table.sort(total)
@ -102,22 +102,22 @@ describe('decor perf', function()
it('can handle long lines with treesitter highlighting', function() it('can handle long lines with treesitter highlighting', function()
Screen.new(100, 51) Screen.new(100, 51)
local result = exec_lua [==[ local result = exec_lua(function()
local long_line = 'local a = { ' .. ('a = 5, '):rep(2000) .. '}' local long_line = 'local a = { ' .. ('a = 5, '):rep(2000) .. '}'
vim.api.nvim_buf_set_lines(0, 0, 0, false, { long_line }) vim.api.nvim_buf_set_lines(0, 0, 0, false, { long_line })
vim.api.nvim_win_set_cursor(0, { 1, 0 }) vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.treesitter.start(0, 'lua') vim.treesitter.start(0, 'lua')
local total = {} local total = {}
for i = 1, 50 do for _ = 1, 50 do
local tic = vim.uv.hrtime() local tic = vim.uv.hrtime()
vim.cmd'redraw!' vim.cmd 'redraw!'
local toc = vim.uv.hrtime() local toc = vim.uv.hrtime()
table.insert(total, toc - tic) table.insert(total, toc - tic)
end end
return { total } return { total }
]==] end)
local total = unpack(result) local total = unpack(result)
table.sort(total) table.sort(total)

View File

@ -49,33 +49,28 @@ describe('treesitter perf', function()
]] ]]
end) end)
local function test_long_line(pos, wrap, line, grid) local function test_long_line(_pos, _wrap, _line, grid)
local screen = Screen.new(20, 11) local screen = Screen.new(20, 11)
local result = exec_lua( local result = exec_lua(function(...)
[==[ local pos, wrap, line = ...
local pos, wrap, line = ...
vim.api.nvim_buf_set_lines(0, 0, 0, false, { line }) vim.api.nvim_buf_set_lines(0, 0, 0, false, { line })
vim.api.nvim_win_set_cursor(0, pos) vim.api.nvim_win_set_cursor(0, pos)
vim.api.nvim_set_option_value('wrap', wrap, { win = 0 }) vim.api.nvim_set_option_value('wrap', wrap, { win = 0 })
vim.treesitter.start(0, 'lua') vim.treesitter.start(0, 'lua')
local total = {} local total = {}
for i = 1, 100 do for _ = 1, 100 do
local tic = vim.uv.hrtime() local tic = vim.uv.hrtime()
vim.cmd'redraw!' vim.cmd 'redraw!'
local toc = vim.uv.hrtime() local toc = vim.uv.hrtime()
table.insert(total, toc - tic) table.insert(total, toc - tic)
end end
return { total } return { total }
]==], end, _pos, _wrap, _line)
pos,
wrap,
line
)
screen:expect({ grid = grid or '' }) screen:expect({ grid = grid or '' })

View File

@ -716,46 +716,44 @@ describe('decorations providers', function()
setup_screen(screen) setup_screen(screen)
local function record() local function record()
exec_lua [[ exec_lua(function()
p_min = { math.huge, math.huge } _G.p_min = { math.huge, math.huge }
p_max = { -math.huge, -math.huge } _G.p_max = { -math.huge, -math.huge }
function pos_gt(a, b) function _G.pos_gt(a, b)
return a[1] > b[1] or (a[1] == b[1] and a[2] > b[2]) return a[1] > b[1] or (a[1] == b[1] and a[2] > b[2])
end end
function pos_lt(a, b) function _G.pos_lt(a, b)
return a[1] < b[1] or (a[1] == b[1] and a[2] < b[2]) return a[1] < b[1] or (a[1] == b[1] and a[2] < b[2])
end end
]] end)
setup_provider [[ setup_provider [[
local function on_do(kind, _, bufnr, br, bc, er, ec) local function on_do(kind, _, bufnr, br, bc, er, ec)
if kind == 'range' then if kind == 'range' then
local b = { br, bc } local b = { br, bc }
local e = { er, ec } local e = { er, ec }
if pos_gt(p_min, b) then if _G.pos_gt(_G.p_min, b) then
p_min = b _G.p_min = b
end end
if pos_lt(p_max, e) then if _G.pos_lt(_G.p_max, e) then
p_max = e _G.p_max = e
end end
end end
end end
]] ]]
end end
local function check(min, max) local function check(min, max)
local function pos_gt(a, b) local p_min = exec_lua('return _G.p_min')
return a[1] > b[1] or (a[1] == b[1] and a[2] > b[2]) assert(
end p_min[1] < min[1] or (p_min[1] == min[1] and p_min[2] <= min[2]),
local function pos_lt(a, b)
return a[1] < b[1] or (a[1] == b[1] and a[2] < b[2])
end
local p_min = exec_lua('return p_min')
assert(not pos_gt(p_min, min),
"minimum position " .. vim.inspect(p_min) "minimum position " .. vim.inspect(p_min)
.. " should be before the first char") .. " should be before the first char"
local p_max = exec_lua('return p_max') )
assert(not pos_lt(p_max, max), local p_max = exec_lua('return _G.p_max')
assert(
p_max[1] > max[1] or (p_max[1] == max[1] and p_max[2] >= max[2]),
"maximum position " .. vim.inspect(p_max) "maximum position " .. vim.inspect(p_max)
.. " should be on or after the last char") .. " should be on or after the last char"
)
end end
-- Multiple lines. -- Multiple lines.