From bef4c226a7b1449a5c274eba4132b225269110cc Mon Sep 17 00:00:00 2001 From: gh-liu Date: Tue, 13 Aug 2024 22:21:06 +0800 Subject: [PATCH] perf: caculate sign char only once --- lua/fold_line/init.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lua/fold_line/init.lua b/lua/fold_line/init.lua index 184eebb..c0be299 100644 --- a/lua/fold_line/init.lua +++ b/lua/fold_line/init.lua @@ -327,14 +327,19 @@ local function on_win(_, winid, bufnr, toprow, botrow) return false end - local one_line_fold = function(i_level, cur_line, cur_line_finfo, prev_line_finfo, next_line_finfo) - if - open_start_sign(i_level, cur_line, cur_line_finfo, prev_line_finfo) - and open_end_sign(i_level, cur_line, cur_line_finfo, next_line_finfo) - then + local fold_sign = function(i_level, cur_line, cur_line_finfo, prev_line_finfo, next_line_finfo) + local start_sign = open_start_sign(i_level, cur_line, cur_line_finfo, prev_line_finfo) + local end_sign = open_end_sign(i_level, cur_line, cur_line_finfo, next_line_finfo) + if start_sign and end_sign then save_fold_end_line(cur_line, i_level, cur_line_finfo) return "" end + if start_sign then + return start_sign + end + if end_sign then + return end_sign + end end local row = toprow @@ -386,9 +391,7 @@ local function on_win(_, winid, bufnr, toprow, botrow) end end sign = sign - or one_line_fold(i_level, cur_line, cur_line_finfo, prev_line_finfo, next_line_finfo) - sign = sign or open_start_sign(i_level, cur_line, cur_line_finfo, prev_line_finfo) - sign = sign or open_end_sign(i_level, cur_line, cur_line_finfo, next_line_finfo) + or fold_sign(i_level, cur_line, cur_line_finfo, prev_line_finfo, next_line_finfo) sign = sign or fold_signs.f_sep if sign ~= "" then