misc: refactor plines_win{,_nofill}()

Add const to params and variables (declare and init on same line).
winheight (param) is bool so replace TRUE/FALSE macros with true/false.
This commit is contained in:
Jan Edmund Lazo 2018-08-02 23:11:25 -04:00
parent 766683622a
commit c51c2f5a65
3 changed files with 41 additions and 39 deletions

View File

@ -1203,16 +1203,15 @@ int get_last_leader_offset(char_u *line, char_u **flags)
/* /*
* Return the number of window lines occupied by buffer line "lnum". * Return the number of window lines occupied by buffer line "lnum".
*/ */
int plines(linenr_T lnum) int plines(const linenr_T lnum)
{ {
return plines_win(curwin, lnum, TRUE); return plines_win(curwin, lnum, true);
} }
int int plines_win(
plines_win ( win_T *const wp,
win_T *wp, const linenr_T lnum,
linenr_T lnum, const bool winheight // when true limit to window height
int winheight /* when TRUE limit to window height */
) )
{ {
/* Check for filler lines above this buffer line. When folded the result /* Check for filler lines above this buffer line. When folded the result
@ -1220,34 +1219,34 @@ plines_win (
return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum); return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum);
} }
int plines_nofill(linenr_T lnum) int plines_nofill(const linenr_T lnum)
{ {
return plines_win_nofill(curwin, lnum, TRUE); return plines_win_nofill(curwin, lnum, true);
} }
int int plines_win_nofill(
plines_win_nofill ( win_T *const wp,
win_T *wp, const linenr_T lnum,
linenr_T lnum, const bool winheight // when true limit to window height
int winheight /* when TRUE limit to window height */
) )
{ {
int lines; if (!wp->w_p_wrap) {
if (!wp->w_p_wrap)
return 1; return 1;
}
if (wp->w_width == 0) if (wp->w_width == 0) {
return 1; return 1;
}
// A folded lines is handled just like an empty line. // A folded lines is handled just like an empty line.
if (lineFolded(wp, lnum)) { if (lineFolded(wp, lnum)) {
return 1; return 1;
} }
lines = plines_win_nofold(wp, lnum); const int lines = plines_win_nofold(wp, lnum);
if (winheight > 0 && lines > wp->w_height) if (winheight && lines > wp->w_height) {
return wp->w_height; return wp->w_height;
}
return lines; return lines;
} }
@ -1347,11 +1346,12 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last)
++count; /* count 1 for "+-- folded" line */ ++count; /* count 1 for "+-- folded" line */
first += x; first += x;
} else { } else {
if (first == wp->w_topline) if (first == wp->w_topline) {
count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill; count += plines_win_nofill(wp, first, true) + wp->w_topfill;
else } else {
count += plines_win(wp, first, TRUE); count += plines_win(wp, first, true);
++first; }
first++;
} }
} }
return count; return count;

View File

@ -990,7 +990,7 @@ static void win_update(win_T *wp)
* when it won't get updated below. */ * when it won't get updated below. */
if (wp->w_p_diff && bot_start > 0) if (wp->w_p_diff && bot_start > 0)
wp->w_lines[0].wl_size = wp->w_lines[0].wl_size =
plines_win_nofill(wp, wp->w_topline, TRUE) plines_win_nofill(wp, wp->w_topline, true)
+ wp->w_topfill; + wp->w_topfill;
} }
} }
@ -1447,12 +1447,13 @@ static void win_update(win_T *wp)
} }
wp->w_lines[idx].wl_lnum = lnum; wp->w_lines[idx].wl_lnum = lnum;
wp->w_lines[idx].wl_valid = TRUE; wp->w_lines[idx].wl_valid = true;
if (row > wp->w_height) { /* past end of screen */ if (row > wp->w_height) { // past end of screen
/* we may need the size of that too long line later on */ // we may need the size of that too long line later on
if (dollar_vcol == -1) if (dollar_vcol == -1) {
wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); wp->w_lines[idx].wl_size = plines_win(wp, lnum, true);
++idx; }
idx++;
break; break;
} }
if (dollar_vcol == -1) if (dollar_vcol == -1)

View File

@ -4848,8 +4848,8 @@ void scroll_to_fraction(win_T *wp, int prev_height)
sline = wp->w_wrow - line_size; sline = wp->w_wrow - line_size;
if (sline >= 0) { if (sline >= 0) {
/* Make sure the whole cursor line is visible, if possible. */ // Make sure the whole cursor line is visible, if possible.
int rows = plines_win(wp, lnum, FALSE); const int rows = plines_win(wp, lnum, false);
if (sline > wp->w_height - rows) { if (sline > wp->w_height - rows) {
sline = wp->w_height - rows; sline = wp->w_height - rows;
@ -4884,12 +4884,13 @@ void scroll_to_fraction(win_T *wp, int prev_height)
--sline; --sline;
break; break;
} }
--lnum; lnum--;
if (lnum == wp->w_topline) if (lnum == wp->w_topline) {
line_size = plines_win_nofill(wp, lnum, TRUE) line_size = plines_win_nofill(wp, lnum, true)
+ wp->w_topfill; + wp->w_topfill;
else } else {
line_size = plines_win(wp, lnum, TRUE); line_size = plines_win(wp, lnum, true);
}
sline -= line_size; sline -= line_size;
} }