From d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 19 Jul 2024 11:00:13 +0100 Subject: 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; ``` --- src/nvim/message.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src/nvim/message.c') diff --git a/src/nvim/message.c b/src/nvim/message.c index 73712489ad..53e5511a5a 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -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(' '); } -- cgit