refactor(plines): remove implicit curwin plines() function

This commit is contained in:
Björn Linse 2021-08-10 22:32:08 +02:00
parent a2909aa35f
commit a177c7df09
8 changed files with 41 additions and 42 deletions

View File

@ -2301,7 +2301,7 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight,
} }
} }
} }
ParserLine plines[] = { ParserLine parser_lines[] = {
{ {
.data = expr.data, .data = expr.data,
.size = expr.size, .size = expr.size,
@ -2309,7 +2309,7 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight,
}, },
{ NULL, 0, false }, { NULL, 0, false },
}; };
ParserLine *plines_p = plines; ParserLine *plines_p = parser_lines;
ParserHighlight colors; ParserHighlight colors;
kvi_init(colors); kvi_init(colors);
ParserHighlight *const colors_p = (highlight ? &colors : NULL); ParserHighlight *const colors_p = (highlight ? &colors : NULL);
@ -2335,7 +2335,7 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight,
ret.items[ret.size++] = (KeyValuePair) { ret.items[ret.size++] = (KeyValuePair) {
.key = STATIC_CSTR_TO_STRING("len"), .key = STATIC_CSTR_TO_STRING("len"),
.value = INTEGER_OBJ((Integer)(pstate.pos.line == 1 .value = INTEGER_OBJ((Integer)(pstate.pos.line == 1
? plines[0].size ? parser_lines[0].size
: pstate.pos.col)), : pstate.pos.col)),
}; };
if (east.err.msg != NULL) { if (east.err.msg != NULL) {

View File

@ -1298,7 +1298,7 @@ struct window_S {
/* /*
* w_cline_height is the number of physical lines taken by the buffer line * w_cline_height is the number of physical lines taken by the buffer line
* that the cursor is on. We use this to avoid extra calls to plines(). * that the cursor is on. We use this to avoid extra calls to plines_win().
*/ */
int w_cline_height; // current size of cursor line int w_cline_height; // current size of cursor line
bool w_cline_folded; // cursor line is folded bool w_cline_folded; // cursor line is folded

View File

@ -2593,7 +2593,7 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline,
ColoredCmdline *const ret_ccline_colors) ColoredCmdline *const ret_ccline_colors)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
ParserLine plines[] = { ParserLine parser_lines[] = {
{ {
.data = (const char *)colored_ccline->cmdbuff, .data = (const char *)colored_ccline->cmdbuff,
.size = STRLEN(colored_ccline->cmdbuff), .size = STRLEN(colored_ccline->cmdbuff),
@ -2601,7 +2601,7 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline,
}, },
{ NULL, 0, false }, { NULL, 0, false },
}; };
ParserLine *plines_p = plines; ParserLine *plines_p = parser_lines;
ParserHighlight colors; ParserHighlight colors;
kvi_init(colors); kvi_init(colors);
ParserState pstate; ParserState pstate;

View File

@ -349,14 +349,6 @@ int get_last_leader_offset(char_u *line, char_u **flags)
return result; return result;
} }
/*
* Return the number of window lines occupied by buffer line "lnum".
*/
int plines(const linenr_T lnum)
{
return plines_win(curwin, lnum, true);
}
int plines_win( int plines_win(
win_T *const wp, win_T *const wp,
const linenr_T lnum, const linenr_T lnum,

View File

@ -236,12 +236,14 @@ retnomove:
if (row < 0) { if (row < 0) {
count = 0; count = 0;
for (first = true; curwin->w_topline > 1; ) { for (first = true; curwin->w_topline > 1; ) {
if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) {
++count; count++;
else } else {
count += plines(curwin->w_topline - 1); count += plines_win(curwin, curwin->w_topline - 1, true);
if (!first && count > -row) }
if (!first && count > -row) {
break; break;
}
first = false; first = false;
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) { if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) {
@ -262,7 +264,7 @@ retnomove:
if (curwin->w_topfill > 0) { if (curwin->w_topfill > 0) {
++count; ++count;
} else { } else {
count += plines(curwin->w_topline); count += plines_win(curwin, curwin->w_topline, true);
} }
if (!first && count > row - curwin->w_height_inner + 1) { if (!first && count > row - curwin->w_height_inner + 1) {

View File

@ -1090,8 +1090,9 @@ bool scrolldown(long line_count, int byfold)
curwin->w_cursor.lnum = 1; curwin->w_cursor.lnum = 1;
else else
curwin->w_cursor.lnum = first - 1; curwin->w_cursor.lnum = first - 1;
} else } else {
wrow -= plines(curwin->w_cursor.lnum--); wrow -= plines_win(curwin, curwin->w_cursor.lnum--, true);
}
curwin->w_valid &= curwin->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
moved = true; moved = true;
@ -1425,11 +1426,12 @@ void scroll_cursor_top(int min_scroll, int always)
: plines_nofill(top); : plines_nofill(top);
used += i; used += i;
if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) { if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) {
if (hasFolding(bot, NULL, &bot)) if (hasFolding(bot, NULL, &bot)) {
/* count one logical line for a sequence of folded lines */ // count one logical line for a sequence of folded lines
++used; used++;
else } else {
used += plines(bot); used += plines_win(curwin, bot, true);
}
} }
if (used > curwin->w_height_inner) { if (used > curwin->w_height_inner) {
break; break;
@ -1809,11 +1811,12 @@ void cursor_correct(void)
int below = curwin->w_filler_rows; /* screen lines below botline */ int below = curwin->w_filler_rows; /* screen lines below botline */
while ((above < above_wanted || below < below_wanted) && topline < botline) { while ((above < above_wanted || below < below_wanted) && topline < botline) {
if (below < below_wanted && (below <= above || above >= above_wanted)) { if (below < below_wanted && (below <= above || above >= above_wanted)) {
if (hasFolding(botline, &botline, NULL)) if (hasFolding(botline, &botline, NULL)) {
++below; below++;
else } else {
below += plines(botline); below += plines_win(curwin, botline, true);
--botline; }
botline--;
} }
if (above < above_wanted && (above < below || below >= below_wanted)) { if (above < above_wanted && (above < below || below >= below_wanted)) {
if (hasFolding(topline, NULL, &topline)) if (hasFolding(topline, NULL, &topline))
@ -2146,12 +2149,12 @@ void halfpage(bool flag, linenr_T Prenum)
else { else {
room += i; room += i;
do { do {
i = plines(curwin->w_botline); i = plines_win(curwin, curwin->w_botline, true);
if (i > room) if (i > room) {
break; break;
(void)hasFolding(curwin->w_botline, NULL, }
&curwin->w_botline); (void)hasFolding(curwin->w_botline, NULL, &curwin->w_botline);
++curwin->w_botline; curwin->w_botline++;
room -= i; room -= i;
} while (curwin->w_botline <= curbuf->b_ml.ml_line_count); } while (curwin->w_botline <= curbuf->b_ml.ml_line_count);
} }

View File

@ -5122,11 +5122,13 @@ static void nv_scroll(cmdarg_T *cap)
--n; --n;
break; break;
} }
used += plines(curwin->w_topline + n); used += plines_win(curwin, curwin->w_topline + n, true);
if (used >= half) if (used >= half) {
break; break;
if (hasFolding(curwin->w_topline + n, NULL, &lnum)) }
if (hasFolding(curwin->w_topline + n, NULL, &lnum)) {
n = lnum - curwin->w_topline; n = lnum - curwin->w_topline;
}
} }
if (n > 0 && used > curwin->w_height_inner) { if (n > 0 && used > curwin->w_height_inner) {
n--; n--;

View File

@ -1694,7 +1694,7 @@ static void win_update(win_T *wp, Providers *providers)
/* /*
* There is a trick with w_botline. If we invalidate it on each * There is a trick with w_botline. If we invalidate it on each
* change that might modify it, this will cause a lot of expensive * change that might modify it, this will cause a lot of expensive
* calls to plines() in update_topline() each time. Therefore the * calls to plines_win() in update_topline() each time. Therefore the
* value of w_botline is often approximated, and this value is used to * value of w_botline is often approximated, and this value is used to
* compute the value of w_topline. If the value of w_botline was * compute the value of w_topline. If the value of w_botline was
* wrong, check that the value of w_topline is correct (cursor is on * wrong, check that the value of w_topline is correct (cursor is on
@ -4119,7 +4119,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
/* /*
* Update w_cline_height and w_cline_folded if the cursor line was * Update w_cline_height and w_cline_folded if the cursor line was
* updated (saves a call to plines() later). * updated (saves a call to plines_win() later).
*/ */
if (wp == curwin && lnum == curwin->w_cursor.lnum) { if (wp == curwin && lnum == curwin->w_cursor.lnum) {
curwin->w_cline_row = startrow; curwin->w_cline_row = startrow;