mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 10:55:40 +00:00
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;
```
This commit is contained in:
committed by
Lewis Russell
parent
1b5a394ffd
commit
d1bd3d643e
@@ -1191,10 +1191,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data)
|
||||
memmove(term->sb_buffer, term->sb_buffer + 1,
|
||||
sizeof(term->sb_buffer[0]) * (term->sb_current));
|
||||
|
||||
size_t cols_to_copy = (size_t)cols;
|
||||
if (cols_to_copy > sbrow->cols) {
|
||||
cols_to_copy = sbrow->cols;
|
||||
}
|
||||
size_t cols_to_copy = MIN((size_t)cols, sbrow->cols);
|
||||
|
||||
// copy to vterm state
|
||||
memcpy(cells, sbrow->cells, sizeof(cells[0]) * cols_to_copy);
|
||||
|
||||
Reference in New Issue
Block a user