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,
.size = expr.size,
@ -2309,7 +2309,7 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight,
},
{ NULL, 0, false },
};
ParserLine *plines_p = plines;
ParserLine *plines_p = parser_lines;
ParserHighlight colors;
kvi_init(colors);
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) {
.key = STATIC_CSTR_TO_STRING("len"),
.value = INTEGER_OBJ((Integer)(pstate.pos.line == 1
? plines[0].size
? parser_lines[0].size
: pstate.pos.col)),
};
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
* 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
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)
FUNC_ATTR_NONNULL_ALL
{
ParserLine plines[] = {
ParserLine parser_lines[] = {
{
.data = (const char *)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 },
};
ParserLine *plines_p = plines;
ParserLine *plines_p = parser_lines;
ParserHighlight colors;
kvi_init(colors);
ParserState pstate;

View File

@ -349,14 +349,6 @@ int get_last_leader_offset(char_u *line, char_u **flags)
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(
win_T *const wp,
const linenr_T lnum,

View File

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

View File

@ -5122,11 +5122,13 @@ static void nv_scroll(cmdarg_T *cap)
--n;
break;
}
used += plines(curwin->w_topline + n);
if (used >= half)
used += plines_win(curwin, curwin->w_topline + n, true);
if (used >= half) {
break;
if (hasFolding(curwin->w_topline + n, NULL, &lnum))
}
if (hasFolding(curwin->w_topline + n, NULL, &lnum)) {
n = lnum - curwin->w_topline;
}
}
if (n > 0 && used > curwin->w_height_inner) {
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
* 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
* 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
@ -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
* updated (saves a call to plines() later).
* updated (saves a call to plines_win() later).
*/
if (wp == curwin && lnum == curwin->w_cursor.lnum) {
curwin->w_cline_row = startrow;