aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/drawline.c
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2023-01-31 00:52:34 +0100
committerLuuk van Baal <luukvbaal@gmail.com>2023-02-04 11:04:43 +0100
commit08fb3b5309dee79585f3eec2450636966cbb01b4 (patch)
tree8569a3aeea80ce77d20056e663f3ec726d267d43 /src/nvim/drawline.c
parent964ae205a583807127eda75d9876fb6dfda6065c (diff)
downloadrneovim-08fb3b5309dee79585f3eec2450636966cbb01b4.tar.gz
rneovim-08fb3b5309dee79585f3eec2450636966cbb01b4.tar.bz2
rneovim-08fb3b5309dee79585f3eec2450636966cbb01b4.zip
perf(column): only build fold/sign column when present in 'statuscolumn'
Problem: The fold and sign column is built and stored regardless of whether the corresponding item is present in 'statuscolumn'. Solution: Since the 'statuscolumn' parses itself, we can defer building the columns until the corresponding item is actually encountered.
Diffstat (limited to 'src/nvim/drawline.c')
-rw-r--r--src/nvim/drawline.c45
1 files changed, 11 insertions, 34 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 01ff207c2b..5281370995 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -404,37 +404,10 @@ static int get_sign_attrs(buf_T *buf, linenr_T lnum, SignTextAttrs *sattrs, int
/// the start of the buffer line "lnum" and once for the wrapped lines.
///
/// @param[out] stcp Status column attributes
-static void get_statuscol_str(win_T *wp, linenr_T lnum, int row, int startrow, int filler_lines,
- int cul_attr, int sign_num_attr, int sign_cul_attr, statuscol_T *stcp,
- foldinfo_T foldinfo, SignTextAttrs *sattrs)
+static void get_statuscol_str(win_T *wp, linenr_T lnum, int virtnum, statuscol_T *stcp)
{
- long relnum = -1;
- bool use_cul = use_cursor_line_sign(wp, lnum);
- int virtnum = row - startrow - filler_lines;
-
- // When called the first time for line "lnum" set num_attr
- if (stcp->num_attr == 0) {
- stcp->num_attr = sign_num_attr ? sign_num_attr
- : get_line_number_attr(wp, lnum, row, startrow, filler_lines);
- }
- // When called for the first non-filler row of line "lnum" set num v:vars and fold column
- if (virtnum == 0) {
- relnum = labs(get_cursor_rel_lnum(wp, lnum));
- if (compute_foldcolumn(wp, 0)) {
- size_t n = fill_foldcolumn(stcp->fold_text, wp, foldinfo, lnum);
- stcp->fold_text[n] = NUL;
- stcp->fold_attr = win_hl_attr(wp, use_cul ? HLF_CLF : HLF_FC);
- }
- }
- // Make sure to clear->set->clear sign column for filler->first->wrapped lines
- int i = 0;
- for (; i < wp->w_scwidth; i++) {
- SignTextAttrs *sattr = virtnum ? NULL : sign_get_attr(i, sattrs, wp->w_scwidth);
- stcp->sign_text[i] = sattr && sattr->text ? sattr->text : " ";
- stcp->sign_attr[i] = sattr ? (use_cul && sign_cul_attr ? sign_cul_attr : sattr->hl_attr_id)
- : win_hl_attr(wp, use_cul ? HLF_CLS : HLF_SC);
- }
- stcp->sign_text[i] = NULL;
+ // When called for the first non-filler row of line "lnum" set num v:vars
+ long relnum = virtnum == 0 ? labs(get_cursor_rel_lnum(wp, lnum)) : -1;
// When a buffer's line count has changed, make a best estimate for the full
// width of the status column by building with "w_nrwidth_line_count". Add
@@ -496,8 +469,7 @@ static void get_statuscol_display_info(statuscol_T *stcp, LineDrawState *draw_st
if (stcp->textp + *n_extrap < stcp->text_end) {
int hl = stcp->hlrecp->userhl;
stcp->textp = stcp->hlrecp->start;
- stcp->cur_attr = hl < 0 ? syn_id2attr(-stcp->hlrecp->userhl)
- : hl > 0 ? hl : stcp->num_attr;
+ stcp->cur_attr = hl < 0 ? syn_id2attr(-hl) : hl > 0 ? hl : stcp->num_attr;
stcp->hlrecp++;
*draw_state = WL_STC - 1;
}
@@ -1211,7 +1183,13 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
if (*wp->w_p_stc != NUL) {
// Draw the 'statuscolumn' if option is set.
statuscol.draw = true;
+ statuscol.sattrs = sattrs;
+ statuscol.foldinfo = foldinfo;
statuscol.width = win_col_off(wp);
+ statuscol.use_cul = use_cursor_line_sign(wp, lnum);
+ statuscol.sign_cul_attr = statuscol.use_cul ? sign_cul_attr : 0;
+ statuscol.num_attr = sign_num_attr ? sign_num_attr
+ : get_line_number_attr(wp, lnum, row, startrow, filler_lines);
}
int sign_idx = 0;
@@ -1357,8 +1335,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
// Draw the 'statuscolumn' if option is set.
if (statuscol.draw) {
if (statuscol.textp == NULL) {
- get_statuscol_str(wp, lnum, row, startrow, filler_lines, cul_attr,
- sign_num_attr, sign_cul_attr, &statuscol, foldinfo, sattrs);
+ get_statuscol_str(wp, lnum, row - startrow - filler_lines, &statuscol);
if (wp->w_redr_statuscol) {
break;
}