mirror of
https://github.com/neovim/neovim.git
synced 2025-12-20 13:25:34 +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
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user