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/drawline.c | |
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/drawline.c')
-rw-r--r-- | src/nvim/drawline.c | 8 |
1 files changed, 2 insertions, 6 deletions
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; |