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:
Lewis Russell
2024-07-19 11:00:13 +01:00
committed by Lewis Russell
parent 1b5a394ffd
commit d1bd3d643e
36 changed files with 419 additions and 1214 deletions

View File

@@ -1384,11 +1384,7 @@ void msgmore(int n)
return;
}
if (n > 0) {
pn = n;
} else {
pn = -n;
}
pn = abs(n);
if (pn > p_report) {
if (n > 0) {
@@ -1426,9 +1422,7 @@ void msg_start(void)
{
bool did_return = false;
if (msg_row < cmdline_row) {
msg_row = cmdline_row;
}
msg_row = MAX(msg_row, cmdline_row);
if (!msg_silent) {
XFREE_CLEAR(keep_msg); // don't display old message now
@@ -3382,9 +3376,7 @@ void msg_advance(int col)
}
return;
}
if (col >= Columns) { // not enough room
col = Columns - 1;
}
col = MIN(col, Columns - 1); // not enough room
while (msg_col < col) {
msg_putchar(' ');
}