Compare commits

..

No commits in common. "35cea0b28d7d1479830489ba65bdf8f499834120" and "fab5cbad0042e46ed035550c66981990f2627018" have entirely different histories.

5 changed files with 74 additions and 61 deletions

View File

@ -1483,13 +1483,16 @@ 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.
decor_providers_invoke_line(wp, lnum - 1, &has_decor);
bool added_decor = false;
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);
line = ml_get_buf(wp->w_buffer, lnum);
ptr = line + col;
}
if (has_decor) {
extra_check = true;
}
@ -3036,16 +3039,18 @@ 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);
col_off = MAX(col_off, 1);
bool added_decor = false;
colnr_T new_col;
if (col_off <= line_len - begin_col) {
int end_col = begin_col + col_off;
end_col += mb_off_next(line, line + end_col);
decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum - 1, end_col, has_decor);
decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum - 1, end_col, &added_decor);
new_col = end_col;
} else {
decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum, 0, has_decor);
decor_providers_invoke_range(wp, lnum - 1, begin_col, lnum, 0, &added_decor);
new_col = INT_MAX;
}
*has_decor |= added_decor;
return new_col;
}

View File

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

View File

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

View File

@ -49,10 +49,11 @@ describe('treesitter perf', function()
]]
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 result = exec_lua(function(...)
local result = exec_lua(
[==[
local pos, wrap, line = ...
vim.api.nvim_buf_set_lines(0, 0, 0, false, { line })
@ -62,7 +63,7 @@ describe('treesitter perf', function()
vim.treesitter.start(0, 'lua')
local total = {}
for _ = 1, 100 do
for i = 1, 100 do
local tic = vim.uv.hrtime()
vim.cmd'redraw!'
local toc = vim.uv.hrtime()
@ -70,7 +71,11 @@ describe('treesitter perf', function()
end
return { total }
end, _pos, _wrap, _line)
]==],
pos,
wrap,
line
)
screen:expect({ grid = grid or '' })

View File

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