mirror of
https://github.com/neovim/neovim.git
synced 2026-08-26 17:11:48 +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
@@ -1269,11 +1269,7 @@ int current_par(oparg_T *oap, int count, bool include, int type)
|
||||
// When visual area is more than one line: extend it.
|
||||
if (VIsual_active && start_lnum != VIsual.lnum) {
|
||||
extend:
|
||||
if (start_lnum < VIsual.lnum) {
|
||||
dir = BACKWARD;
|
||||
} else {
|
||||
dir = FORWARD;
|
||||
}
|
||||
dir = start_lnum < VIsual.lnum ? BACKWARD : FORWARD;
|
||||
for (int i = count; --i >= 0;) {
|
||||
if (start_lnum ==
|
||||
(dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) {
|
||||
|
||||
Reference in New Issue
Block a user