diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2024-07-19 11:00:13 +0100 |
|---|---|---|
| committer | Lewis Russell <me@lewisr.dev> | 2024-07-30 22:43:29 +0100 |
| commit | d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0 (patch) | |
| tree | ca5a4a60fca9e814d0a3937cc4ff21ed9e037520 /src/nvim | |
| parent | 1b5a394ffd4bb638ec9cbbb5e4d12d11225389cf (diff) | |
| download | rneovim-d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0.tar.gz rneovim-d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0.tar.bz2 rneovim-d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0.zip | |
refactor: collapse statements in single assignments
Problem:
Variables are often assigned multiple places in common patterns.
Solution:
Replace these common patterns with different patterns that reduce the
number of assignments.
Use `MAX` and `MIN`:
```c
if (x < y) {
x = y;
}
// -->
x = MAX(x, y);
```
```c
if (x > y) {
x = y;
}
// -->
x = MIN(x, y);
```
Use ternary:
```c
int a;
if (cond) {
a = b;
} els {
a = c;
}
// -->
int a = cond ? b : c;
```
Diffstat (limited to 'src/nvim')
36 files changed, 419 insertions, 1214 deletions
diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 700bfc1655..e3a2db75e5 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -346,12 +346,7 @@ static void alist_add_list(int count, char **files, int after, bool will_edit) int old_argcount = ARGCOUNT; ga_grow(&ALIST(curwin)->al_ga, count); if (check_arglist_locked() != FAIL) { - if (after < 0) { - after = 0; - } - if (after > ARGCOUNT) { - after = ARGCOUNT; - } + after = MIN(MAX(after, 0), ARGCOUNT); if (after < ARGCOUNT) { memmove(&(ARGLIST[after + count]), &(ARGLIST[after]), (size_t)(ARGCOUNT - after) * sizeof(aentry_T)); diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d1b7c553c3..2fc684b412 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1262,17 +1262,8 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags) if (bp == NULL) { bp = buf; } - if (dir == FORWARD) { - buf = buf->b_next; - if (buf == NULL) { - buf = firstbuf; - } - } else { - buf = buf->b_prev; - if (buf == NULL) { - buf = lastbuf; - } - } + buf = dir == FORWARD ? (buf->b_next != NULL ? buf->b_next : firstbuf) + : (buf->b_prev != NULL ? buf->b_prev : lastbuf); // Don't count unlisted buffers. // Avoid non-help buffers if the starting point was a non-help buffer and // vice-versa. @@ -1505,11 +1496,7 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags) bp = buf; } } - if (forward) { - buf = buf->b_next; - } else { - buf = buf->b_prev; - } + buf = forward ? buf->b_next : buf->b_prev; } } if (buf == NULL) { // No loaded buffer, use unloaded one @@ -1524,11 +1511,7 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags) } } if (buf == NULL) { // Still no buffer, just take one - if (curbuf->b_next != NULL) { - buf = curbuf->b_next; - } else { - buf = curbuf->b_prev; - } + buf = curbuf->b_next != NULL ? curbuf->b_next : curbuf->b_prev; if (bt_quickfix(buf)) { buf = NULL; } @@ -1679,11 +1662,7 @@ void set_curbuf(buf_T *buf, int action, bool update_jumplist) } // If the buffer is not valid but curwin->w_buffer is NULL we must // enter some buffer. Using the last one is hopefully OK. - if (!valid) { - enter_buffer(lastbuf); - } else { - enter_buffer(buf); - } + enter_buffer(valid ? buf : lastbuf); if (old_tw != curbuf->b_p_tw) { check_colorcolumn(curwin); } @@ -2135,7 +2114,6 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit) { win_T *wp = NULL; fmark_T *fm = NULL; - colnr_T col; buf_T *buf = buflist_findnr(n); if (buf == NULL) { @@ -2156,6 +2134,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit) return FAIL; } + colnr_T col; bool restore_view = false; // altfpos may be changed by getfile(), get it now if (lnum == 0) { @@ -2291,11 +2270,7 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted, int match = -1; if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) { - if (*pattern == '%') { - match = curbuf->b_fnum; - } else { - match = curwin->w_alt_fnum; - } + match = *pattern == '%' ? curbuf->b_fnum : curwin->w_alt_fnum; buf_T *found_buf = buflist_findnr(match); if (diffmode && !(found_buf && diff_mode_buf(found_buf))) { match = -1; @@ -2906,9 +2881,7 @@ void buflist_list(exarg_T *eap) changed_char, NameBuff); - if (len > IOSIZE - 20) { - len = IOSIZE - 20; - } + len = MIN(len, IOSIZE - 20); // put "line 999" in column 40 or after the file name int i = 40 - vim_strsize(IObuff); @@ -3212,8 +3185,6 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id) /// @param fullname when non-zero print full path void fileinfo(int fullname, int shorthelp, bool dont_truncate) { - char *name; - int n; char *p; char *buffer = xmalloc(IOSIZE); @@ -3229,11 +3200,9 @@ void fileinfo(int fullname, int shorthelp, bool dont_truncate) if (buf_spname(curbuf) != NULL) { xstrlcpy(p, buf_spname(curbuf), (size_t)(IOSIZE - (p - buffer))); } else { - if (!fullname && curbuf->b_fname != NULL) { - name = curbuf->b_fname; - } else { - name = curbuf->b_ffname; - } + char *name = (!fullname && curbuf->b_fname != NULL) + ? curbuf->b_fname + : curbuf->b_ffname; home_replace(shorthelp ? curbuf : NULL, name, p, (size_t)(IOSIZE - (p - buffer)), true); } @@ -3254,6 +3223,7 @@ void fileinfo(int fullname, int shorthelp, bool dont_truncate) || (curbuf->b_flags & BF_WRITE_MASK) || curbuf->b_p_ro) ? " " : ""); + int n; // With 32 bit longs and more than 21,474,836 lines multiplying by 100 // causes an overflow, thus for large numbers divide instead. if (curwin->w_cursor.lnum > 1000000) { @@ -3342,10 +3312,7 @@ void maketitle(void) if (p_title) { if (p_titlelen > 0) { - maxlen = (int)(p_titlelen * Columns / 100); - if (maxlen < 10) { - maxlen = 10; - } + maxlen = MAX((int)(p_titlelen * Columns / 100), 10); } if (*p_titlestring != NUL) { @@ -3461,12 +3428,9 @@ void maketitle(void) icon_str = p_iconstring; } } else { - char *buf_p; - if (buf_spname(curbuf) != NULL) { - buf_p = buf_spname(curbuf); - } else { // use file name only in icon - buf_p = path_tail(curbuf->b_ffname); - } + char *buf_p = buf_spname(curbuf) != NULL + ? buf_spname(curbuf) + : path_tail(curbuf->b_ffname); // use file name only in icon *icon_str = NUL; // Truncate name at 100 bytes. int len = (int)strlen(buf_p); @@ -3631,23 +3595,18 @@ bool bt_prompt(buf_T *buf) /// Open a window for a number of buffers. void ex_buffer_all(exarg_T *eap) { - win_T *wp, *wpnext; + win_T *wpnext; int split_ret = OK; int open_wins = 0; - linenr_T count; // Maximum number of windows to open. - int all; // When true also load inactive buffers. int had_tab = cmdmod.cmod_tab; - if (eap->addr_count == 0) { // make as many windows as possible - count = 9999; - } else { - count = eap->line2; // make as many windows as specified - } - if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) { - all = false; - } else { - all = true; - } + // Maximum number of windows to open. + linenr_T count = eap->addr_count == 0 + ? 9999 // make as many windows as possible + : eap->line2; // make as many windows as specified + + // When true also load inactive buffers. + int all = eap->cmdidx != CMD_unhide && eap->cmdidx != CMD_sunhide; // Stop Visual mode, the cursor and "VIsual" may very well be invalid after // switching to another buffer. @@ -3663,7 +3622,7 @@ void ex_buffer_all(exarg_T *eap) while (true) { tabpage_T *tpnext = curtab->tp_next; // Try to close floating windows first - for (wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) { + for (win_T *wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) { wpnext = wp->w_floating ? wp->w_prev->w_floating ? wp->w_prev : firstwin : (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next; @@ -3712,13 +3671,12 @@ void ex_buffer_all(exarg_T *eap) continue; } + win_T *wp; if (had_tab != 0) { // With the ":tab" modifier don't move the window. - if (buf->b_nwindows > 0) { - wp = lastwin; // buffer has a window, skip it - } else { - wp = NULL; - } + wp = buf->b_nwindows > 0 + ? lastwin // buffer has a window, skip it + : NULL; } else { // Check if this buffer already has a window for (wp = firstwin; wp != NULL; wp = wp->w_next) { @@ -3794,7 +3752,7 @@ void ex_buffer_all(exarg_T *eap) autocmd_no_leave--; // Close superfluous windows. - for (wp = lastwin; open_wins > count;) { + for (win_T *wp = lastwin; open_wins > count;) { bool r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) || autowrite(wp->w_buffer, false) == OK) && !is_aucmd_win(wp); if (!win_valid(wp)) { @@ -3862,7 +3820,6 @@ static int chk_modeline(linenr_T lnum, int flags) { char *s; char *e; - char *linecopy; // local copy of any modeline found intmax_t vers; int retval = OK; @@ -3907,6 +3864,7 @@ static int chk_modeline(linenr_T lnum, int flags) s++; } while (s[-1] != ':'); + char *linecopy; // local copy of any modeline found s = linecopy = xstrdup(s); // copy the line, it will change // prepare for emsg() diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index 9f6eb8c9e8..fa0a55e7b6 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -261,11 +261,8 @@ static int buf_write_convert(struct bw_info *ip, char **bufp, int *lenp) ip->bw_restlen += *lenp; break; } - if (n > 1) { - c = (unsigned)utf_ptr2char((char *)ip->bw_rest); - } else { - c = ip->bw_rest[0]; - } + c = (n > 1) ? (unsigned)utf_ptr2char((char *)ip->bw_rest) + : ip->bw_rest[0]; if (n >= ip->bw_restlen) { n -= ip->bw_restlen; ip->bw_restlen = 0; @@ -289,11 +286,8 @@ static int buf_write_convert(struct bw_info *ip, char **bufp, int *lenp) (size_t)ip->bw_restlen); break; } - if (n > 1) { - c = (unsigned)utf_ptr2char(*bufp + wlen); - } else { - c = (uint8_t)(*bufp)[wlen]; - } + c = n > 1 ? (unsigned)utf_ptr2char(*bufp + wlen) + : (uint8_t)(*bufp)[wlen]; } if (ucs2bytes(c, &p, flags) && !ip->bw_conv_error) { @@ -876,9 +870,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o // Change one character, just before the extension. // char *wp = *backupp + strlen(*backupp) - 1 - strlen(backup_ext); - if (wp < *backupp) { // empty file name ??? - wp = *backupp; - } + wp = MAX(wp, *backupp); // empty file name ??? *wp = 'z'; while (*wp > 'a' && os_fileinfo(*backupp, &file_info_new)) { (*wp)--; @@ -993,9 +985,7 @@ nobackup: // Change one character, just before the extension. if (!p_bk && os_path_exists(*backupp)) { p = *backupp + strlen(*backupp) - 1 - strlen(backup_ext); - if (p < *backupp) { // empty file name ??? - p = *backupp; - } + p = MAX(p, *backupp); // empty file name ??? *p = 'z'; while (*p > 'a' && os_path_exists(*backupp)) { (*p)--; @@ -1255,9 +1245,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en status_redraw_all(); // redraw status lines later } - if (end > buf->b_ml.ml_line_count) { - end = buf->b_ml.ml_line_count; - } + end = MIN(end, buf->b_ml.ml_line_count); if (buf->b_ml.ml_flags & ML_EMPTY) { start = end + 1; } diff --git a/src/nvim/change.c b/src/nvim/change.c index 428a9187c8..6e9fab5a9b 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -523,19 +523,13 @@ void changed_lines_redraw_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, linenr_ { if (buf->b_mod_set) { // find the maximum area that must be redisplayed - if (lnum < buf->b_mod_top) { - buf->b_mod_top = lnum; - } + buf->b_mod_top = MIN(buf->b_mod_top, lnum); if (lnum < buf->b_mod_bot) { // adjust old bot position for xtra lines buf->b_mod_bot += xtra; - if (buf->b_mod_bot < lnum) { - buf->b_mod_bot = lnum; - } - } - if (lnume + xtra > buf->b_mod_bot) { - buf->b_mod_bot = lnume + xtra; + buf->b_mod_bot = MAX(buf->b_mod_bot, lnum); } + buf->b_mod_bot = MAX(buf->b_mod_bot, lnume + xtra); buf->b_mod_xlines += xtra; } else { // set the area that must be redisplayed @@ -2262,9 +2256,7 @@ int get_last_leader_offset(char *line, char **flags) for (int off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) { off--; if (!strncmp(string + off, com_leader, (size_t)(len2 - off))) { - if (i - off < lower_check_bound) { - lower_check_bound = i - off; - } + lower_check_bound = MIN(lower_check_bound, i - off); } } } diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index e1a282cb0b..402a891099 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -670,10 +670,7 @@ static char *get_next_or_prev_match(int mode, expand_T *xp) ht -= 2; } findex -= ht; - if (findex < 0) { - // few entries left, select the first entry - findex = 0; - } + findex = MAX(findex, 0); // few entries left, select the first entry } } else if (mode == WILD_PAGEDOWN) { if (findex == xp->xp_numfiles - 1) { @@ -701,18 +698,10 @@ static char *get_next_or_prev_match(int mode, expand_T *xp) // When wrapping around, return the original string, set findex to -1. if (findex < 0) { - if (xp->xp_orig == NULL) { - findex = xp->xp_numfiles - 1; - } else { - findex = -1; - } + findex = xp->xp_orig == NULL ? xp->xp_numfiles - 1 : -1; } if (findex >= xp->xp_numfiles) { - if (xp->xp_orig == NULL) { - findex = 0; - } else { - findex = -1; - } + findex = xp->xp_orig == NULL ? 0 : -1; } if (compl_match_array) { compl_selected = findex; @@ -1112,9 +1101,7 @@ int showmatches(expand_T *xp, bool wildmenu) } else { j = vim_strsize(SHOW_MATCH(i)); } - if (j > maxlen) { - maxlen = j; - } + maxlen = MAX(maxlen, j); } if (xp->xp_context == EXPAND_TAGS_LISTFILES) { diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 2e9e68843a..35afca2fe9 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -216,12 +216,7 @@ static int coladvance2(win_T *wp, pos_T *pos, bool addspaces, bool finetune, col } } - if (idx < 0) { - pos->col = 0; - } else { - pos->col = idx; - } - + pos->col = MAX(idx, 0); pos->coladd = 0; if (finetune) { @@ -310,15 +305,9 @@ linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum) /// This allows for the col to be on the NUL byte. void check_pos(buf_T *buf, pos_T *pos) { - if (pos->lnum > buf->b_ml.ml_line_count) { - pos->lnum = buf->b_ml.ml_line_count; - } - + pos->lnum = MIN(pos->lnum, buf->b_ml.ml_line_count); if (pos->col > 0) { - colnr_T len = ml_get_buf_len(buf, pos->lnum); - if (pos->col > len) { - pos->col = len; - } + pos->col = MIN(pos->col, ml_get_buf_len(buf, pos->lnum)); } } @@ -385,9 +374,7 @@ void check_cursor_col(win_T *win) int cs, ce; getvcol(win, &win->w_cursor, &cs, NULL, &ce); - if (win->w_cursor.coladd > ce - cs) { - win->w_cursor.coladd = ce - cs; - } + win->w_cursor.coladd = MIN(win->w_cursor.coladd, ce - cs); } } else { // avoid weird number when there is a miscalculation or overflow diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 45bcb94a1f..0b9bdb6181 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -694,7 +694,7 @@ void diff_redraw(bool dofold) if (((wp != curwin) && (wp->w_topfill > 0)) || (n > 0)) { if (wp->w_topfill > n) { - wp->w_topfill = (n < 0 ? 0 : n); + wp->w_topfill = MAX(n, 0); } else if ((n > 0) && (n > wp->w_topfill)) { wp->w_topfill = n; if (wp == curwin) { @@ -2679,9 +2679,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) si_org -= utf_head_off(line_org, line_org + si_org); si_new -= utf_head_off(line_new, line_new + si_new); - if (*startp > si_org) { - *startp = si_org; - } + *startp = MIN(*startp, si_org); // Search for end of difference, if any. if ((line_org[si_org] != NUL) || (line_new[si_new] != NUL)) { @@ -2721,9 +2719,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) } } - if (*endp < ei_org) { - *endp = ei_org; - } + *endp = MAX(*endp, ei_org); } } } @@ -3051,19 +3047,11 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr // range ends above end of current/from diff block if (idx_cur == idx_from) { // :diffput - int i = dp->df_count[idx_cur] - start_skip - end_skip; - - if (count > i) { - count = i; - } + count = MIN(count, dp->df_count[idx_cur] - start_skip - end_skip); } else { // :diffget count -= end_skip; - end_skip = dp->df_count[idx_from] - start_skip - count; - - if (end_skip < 0) { - end_skip = 0; - } + end_skip = MAX(dp->df_count[idx_from] - start_skip - count, 0); } } else { end_skip = 0; @@ -3249,9 +3237,7 @@ int diff_move_to(int dir, int count) } // don't end up past the end of the file - if (lnum > curbuf->b_ml.ml_line_count) { - lnum = curbuf->b_ml.ml_line_count; - } + lnum = MIN(lnum, curbuf->b_ml.ml_line_count); // When the cursor didn't move at all we fail. if (lnum == curwin->w_cursor.lnum) { @@ -3297,10 +3283,7 @@ static linenr_T diff_get_corresponding_line_int(buf_T *buf1, linenr_T lnum1) if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) { // Inside the diffblock baseline = lnum1 - dp->df_lnum[idx1]; - - if (baseline > dp->df_count[idx2]) { - baseline = dp->df_count[idx2]; - } + baseline = MIN(baseline, dp->df_count[idx2]); return dp->df_lnum[idx2] + baseline; } @@ -3335,10 +3318,7 @@ linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1) linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1); // don't end up past the end of the file - if (lnum > curbuf->b_ml.ml_line_count) { - return curbuf->b_ml.ml_line_count; - } - return lnum; + return MIN(lnum, curbuf->b_ml.ml_line_count); } /// For line "lnum" in the current window find the equivalent lnum in window @@ -3381,10 +3361,7 @@ linenr_T diff_lnum_win(linenr_T lnum, win_T *wp) } linenr_T n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); - if (n > dp->df_lnum[i] + dp->df_count[i]) { - n = dp->df_lnum[i] + dp->df_count[i]; - } - return n; + return MIN(n, dp->df_lnum[i] + dp->df_count[i]); } /// Handle an ED style diff line. diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 14b3b3e693..47d84e6539 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -886,9 +886,7 @@ static int get_rightmost_vcol(win_T *wp, const int *color_cols) if (color_cols) { // determine rightmost colorcolumn to possibly draw for (int i = 0; color_cols[i] >= 0; i++) { - if (ret < color_cols[i]) { - ret = color_cols[i]; - } + ret = MAX(ret, color_cols[i]); } } @@ -2560,9 +2558,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. // check if line ends before left margin - if (wlv.vcol < start_col + wlv.col - win_col_off(wp)) { - wlv.vcol = start_col + wlv.col - win_col_off(wp); - } + wlv.vcol = MAX(wlv.vcol, start_col + wlv.col - win_col_off(wp)); // Get rid of the boguscols now, we want to draw until the right // edge for 'cursorcolumn'. wlv.col -= wlv.boguscols; diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 770f8da6cf..425651b60e 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -395,18 +395,9 @@ void screen_resize(int width, int height) void check_screensize(void) { // Limit Rows and Columns to avoid an overflow in Rows * Columns. - if (Rows < min_rows()) { - // need room for one window and command line - Rows = min_rows(); - } else if (Rows > 1000) { - Rows = 1000; - } - - if (Columns < MIN_COLUMNS) { - Columns = MIN_COLUMNS; - } else if (Columns > 10000) { - Columns = 10000; - } + // need room for one window and command line + Rows = MIN(MAX(Rows, min_rows()), 1000); + Columns = MIN(MAX(Columns, MIN_COLUMNS), 10000); } /// Return true if redrawing should currently be done. @@ -996,12 +987,9 @@ int showmode(void) } if (edit_submode_extra != NULL) { msg_puts_attr(" ", attr); // Add a space in between. - int sub_attr; - if (edit_submode_highl < HLF_COUNT) { - sub_attr = win_hl_attr(curwin, (int)edit_submode_highl); - } else { - sub_attr = attr; - } + int sub_attr = edit_submode_highl < HLF_COUNT + ? win_hl_attr(curwin, (int)edit_submode_highl) + : attr; msg_puts_attr(edit_submode_extra, sub_attr); } } @@ -1564,9 +1552,7 @@ static void win_update(win_T *wp) // in a pattern match. if (syntax_present(wp)) { mod_top -= buf->b_s.b_syn_sync_linebreaks; - if (mod_top < 1) { - mod_top = 1; - } + mod_top = MAX(mod_top, 1); } } if (mod_bot == 0 || mod_bot < buf->b_mod_bot) { @@ -1635,17 +1621,13 @@ static void win_update(win_T *wp) } hasFolding(wp, mod_top, &mod_top, NULL); - if (mod_top > lnumt) { - mod_top = lnumt; - } + mod_top = MIN(mod_top, lnumt); // Now do the same for the bottom line (one above mod_bot). mod_bot--; hasFolding(wp, mod_bot, NULL, &mod_bot); mod_bot++; - if (mod_bot < lnumb) { - mod_bot = lnumb; - } + mod_bot = MAX(mod_bot, lnumb); } // When a change starts above w_topline and the end is below @@ -1865,18 +1847,8 @@ static void win_update(win_T *wp) to = curwin->w_cursor.lnum; } // redraw more when the cursor moved as well - if (wp->w_old_cursor_lnum < from) { - from = wp->w_old_cursor_lnum; - } - if (wp->w_old_cursor_lnum > to) { - to = wp->w_old_cursor_lnum; - } - if (wp->w_old_visual_lnum < from) { - from = wp->w_old_visual_lnum; - } - if (wp->w_old_visual_lnum > to) { - to = wp->w_old_visual_lnum; - } + from = MIN(MIN(from, wp->w_old_cursor_lnum), wp->w_old_visual_lnum); + to = MAX(MAX(to, wp->w_old_cursor_lnum), wp->w_old_visual_lnum); } else { // Find the line numbers that need to be updated: The lines // between the old cursor position and the current cursor @@ -1898,15 +1870,8 @@ static void win_update(win_T *wp) && wp->w_old_visual_lnum != 0) { from = wp->w_old_visual_lnum; } - if (wp->w_old_visual_lnum > to) { - to = wp->w_old_visual_lnum; - } - if (VIsual.lnum < from) { - from = VIsual.lnum; - } - if (VIsual.lnum > to) { - to = VIsual.lnum; - } + to = MAX(MAX(to, wp->w_old_visual_lnum), VIsual.lnum); + from = MIN(from, VIsual.lnum); } } @@ -1941,9 +1906,7 @@ static void win_update(win_T *wp) pos.col = (colnr_T)strlen(ml_get_buf(wp->w_buffer, pos.lnum)); getvvcol(wp, &pos, NULL, NULL, &t); - if (toc < t) { - toc = t; - } + toc = MAX(toc, t); } toc++; } else { @@ -1953,12 +1916,8 @@ static void win_update(win_T *wp) if (fromc != wp->w_old_cursor_fcol || toc != wp->w_old_cursor_lcol) { - if (from > VIsual.lnum) { - from = VIsual.lnum; - } - if (to < VIsual.lnum) { - to = VIsual.lnum; - } + from = MIN(from, VIsual.lnum); + to = MAX(to, VIsual.lnum); } wp->w_old_cursor_fcol = fromc; wp->w_old_cursor_lcol = toc; |