aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-07-26 16:01:31 +0100
committerLewis Russell <me@lewisr.dev>2024-07-27 14:10:30 +0100
commit6162c937abbf80195ccab3daeb7ecdeb6ab24b52 (patch)
treeee089e91e05e586d38abb497b1257011ca23eff2 /src
parent8bdfc2ab2b2565f06d41921d57a0c6184a097271 (diff)
downloadrneovim-6162c937abbf80195ccab3daeb7ecdeb6ab24b52.tar.gz
rneovim-6162c937abbf80195ccab3daeb7ecdeb6ab24b52.tar.bz2
rneovim-6162c937abbf80195ccab3daeb7ecdeb6ab24b52.zip
refactor(decor): decor_virt_lines()
Reduce calls to hasFolding() and remove the has_fold argument. For lines that don't have virtual lines this should be more efficient as it should avoid any calls to hasFolding(), whereas before it was called at least once for any buffer containing at least one virtual line. This will be slightly less efficient for lines with multiple virtual lines marks as hasFolding() is called once for each mark. This could be optimized, but having multiple virtual lines marks on a single line is very rare.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/decoration.c25
-rw-r--r--src/nvim/drawline.c2
-rw-r--r--src/nvim/plines.c2
3 files changed, 10 insertions, 19 deletions
diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c
index 9c4a65b856..fb6a92025f 100644
--- a/src/nvim/decoration.c
+++ b/src/nvim/decoration.c
@@ -887,8 +887,7 @@ bool decor_redraw_eol(win_T *wp, DecorState *state, int *eol_attr, int eol_col)
static const uint32_t lines_filter[4] = {[kMTMetaLines] = kMTFilterSelect };
-/// @param has_fold whether line "lnum" has a fold, or kNone when not calculated yet
-int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines, TriState has_fold)
+int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines)
{
buf_T *buf = wp->w_buffer;
if (!buf_meta_total(buf, kMTMetaLines)) {
@@ -898,20 +897,11 @@ int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines, TriState has_fo
}
assert(lnum > 0);
- bool below_fold = lnum > 1 && hasFolding(wp, lnum - 1, NULL, NULL);
- if (has_fold == kNone) {
- has_fold = hasFolding(wp, lnum, NULL, NULL);
- }
-
- const int row = lnum - 1;
- const int start_row = below_fold ? row : MAX(row - 1, 0);
- const int end_row = has_fold ? row : row + 1;
- if (start_row >= end_row) {
- return 0;
- }
+ int row = lnum - 1;
MarkTreeIter itr[1] = { 0 };
- if (!marktree_itr_get_filter(buf->b_marktree, start_row, 0, end_row, 0, lines_filter, itr)) {
+ if (!marktree_itr_get_filter(buf->b_marktree, MAX(row - 1, 0), 0, row + 1, 0,
+ lines_filter, itr)) {
return 0;
}
@@ -923,8 +913,9 @@ int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines, TriState has_fo
while (vt) {
if (vt->flags & kVTIsLines) {
bool above = vt->flags & kVTLinesAbove;
- int draw_row = mark.pos.row + (above ? 0 : 1);
- if (draw_row == row) {
+ int mrow = mark.pos.row;
+ int draw_row = mrow + (above ? 0 : 1);
+ if (draw_row == row && !hasFolding(wp, mrow + 1, NULL, NULL)) {
virt_lines += (int)kv_size(vt->data.virt_lines);
if (lines) {
kv_splice(*lines, vt->data.virt_lines);
@@ -935,7 +926,7 @@ int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines, TriState has_fo
}
}
- if (!marktree_itr_next_filter(buf->b_marktree, itr, end_row, 0, lines_filter)) {
+ if (!marktree_itr_next_filter(buf->b_marktree, itr, row + 1, 0, lines_filter)) {
break;
}
}
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 579b237af6..14b3b3e693 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -1158,7 +1158,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
area_highlighting = true;
}
VirtLines virt_lines = KV_INITIAL_VALUE;
- wlv.n_virt_lines = decor_virt_lines(wp, lnum, &virt_lines, has_fold);
+ wlv.n_virt_lines = decor_virt_lines(wp, lnum, &virt_lines);
wlv.filler_lines += wlv.n_virt_lines;
if (lnum == wp->w_topline) {
wlv.filler_lines = wp->w_topfill;
diff --git a/src/nvim/plines.c b/src/nvim/plines.c
index c546099f58..4409b14ae1 100644
--- a/src/nvim/plines.c
+++ b/src/nvim/plines.c
@@ -712,7 +712,7 @@ bool win_may_fill(win_T *wp)
/// @return Number of filler lines above lnum
int win_get_fill(win_T *wp, linenr_T lnum)
{
- int virt_lines = decor_virt_lines(wp, lnum, NULL, kNone);
+ int virt_lines = decor_virt_lines(wp, lnum, NULL);
// be quick when there are no filler lines
if (diffopt_filler()) {