mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +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
@@ -888,10 +888,7 @@ retry:
|
||||
// Use buffer >= 64K. Add linerest to double the size if the
|
||||
// line gets very long, to avoid a lot of copying. But don't
|
||||
// read more than 1 Mbyte at a time, so we can be interrupted.
|
||||
size = 0x10000 + linerest;
|
||||
if (size > 0x100000) {
|
||||
size = 0x100000;
|
||||
}
|
||||
size = MIN(0x10000 + linerest, 0x100000);
|
||||
}
|
||||
|
||||
// Protect against the argument of lalloc() going negative.
|
||||
@@ -2800,9 +2797,7 @@ int check_timestamps(int focus)
|
||||
bufref_T bufref;
|
||||
set_bufref(&bufref, buf);
|
||||
const int n = buf_check_timestamp(buf);
|
||||
if (didit < n) {
|
||||
didit = n;
|
||||
}
|
||||
didit = MAX(didit, n);
|
||||
if (n > 0 && !bufref_valid(&bufref)) {
|
||||
// Autocommands have removed the buffer, start at the first one again.
|
||||
buf = firstbuf;
|
||||
@@ -3192,11 +3187,7 @@ void buf_reload(buf_T *buf, int orig_mode, bool reload_options)
|
||||
|
||||
// Restore the topline and cursor position and check it (lines may
|
||||
// have been removed).
|
||||
if (old_topline > curbuf->b_ml.ml_line_count) {
|
||||
curwin->w_topline = curbuf->b_ml.ml_line_count;
|
||||
} else {
|
||||
curwin->w_topline = old_topline;
|
||||
}
|
||||
curwin->w_topline = MIN(old_topline, curbuf->b_ml.ml_line_count);
|
||||
curwin->w_cursor = old_cursor;
|
||||
check_cursor(curwin);
|
||||
update_topline(curwin);
|
||||
|
Reference in New Issue
Block a user