vim-patch:9.0.1158: code is indented more than necessary (#21697)

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes vim/vim#11787)

7f8b2559a3

Omit reset_last_used_map(): only used in Vim9 script.

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2023-01-09 07:16:36 +08:00
committed by GitHub
parent 904c13e6b5
commit a174f4e53f
3 changed files with 82 additions and 58 deletions

View File

@@ -1150,10 +1150,12 @@ static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr)
{ {
// check for NULL pointer, not to return an error to the user, but // check for NULL pointer, not to return an error to the user, but
// to prevent a crash // to prevent a crash
if (stack_ptr != NULL) { if (stack_ptr == NULL) {
stack_ptr->ffs_prev = search_ctx->ffsc_stack_ptr; return;
search_ctx->ffsc_stack_ptr = stack_ptr;
} }
stack_ptr->ffs_prev = search_ctx->ffsc_stack_ptr;
search_ctx->ffsc_stack_ptr = stack_ptr;
} }
/// Pop a dir from the directory stack. /// Pop a dir from the directory stack.

View File

@@ -477,12 +477,15 @@ static void newFoldLevelWin(win_T *wp)
/// Apply 'foldlevel' to all folds that don't contain the cursor. /// Apply 'foldlevel' to all folds that don't contain the cursor.
void foldCheckClose(void) void foldCheckClose(void)
{ {
if (*p_fcl != NUL) { // can only be "all" right now if (*p_fcl == NUL) {
checkupdate(curwin); return;
if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum, }
(int)curwin->w_p_fdl)) {
changed_window_setting(); // can only be "all" right now
} checkupdate(curwin);
if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum,
(int)curwin->w_p_fdl)) {
changed_window_setting();
} }
} }
@@ -1005,15 +1008,18 @@ void foldAdjustVisual(void)
if (hasFolding(start->lnum, &start->lnum, NULL)) { if (hasFolding(start->lnum, &start->lnum, NULL)) {
start->col = 0; start->col = 0;
} }
if (hasFolding(end->lnum, NULL, &end->lnum)) {
ptr = ml_get(end->lnum); if (!hasFolding(end->lnum, NULL, &end->lnum)) {
end->col = (colnr_T)strlen(ptr); return;
if (end->col > 0 && *p_sel == 'o') {
end->col--;
}
// prevent cursor from moving on the trail byte
mb_adjust_cursor();
} }
ptr = ml_get(end->lnum);
end->col = (colnr_T)strlen(ptr);
if (end->col > 0 && *p_sel == 'o') {
end->col--;
}
// prevent cursor from moving on the trail byte
mb_adjust_cursor();
} }
// cursor_foldstart() {{{2 // cursor_foldstart() {{{2
@@ -1115,10 +1121,12 @@ static int foldLevelWin(win_T *wp, linenr_T lnum)
/// Check if the folds in window "wp" are invalid and update them if needed. /// Check if the folds in window "wp" are invalid and update them if needed.
static void checkupdate(win_T *wp) static void checkupdate(win_T *wp)
{ {
if (wp->w_foldinvalid) { if (!wp->w_foldinvalid) {
foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); // will update all return;
wp->w_foldinvalid = false;
} }
foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); // will update all
wp->w_foldinvalid = false;
} }
// setFoldRepeat() {{{2 // setFoldRepeat() {{{2

View File

@@ -272,10 +272,12 @@ static void delete_buff_tail(buffheader_T *buf, int slen)
return; // nothing to delete return; // nothing to delete
} }
len = (int)strlen(buf->bh_curr->b_str); len = (int)strlen(buf->bh_curr->b_str);
if (len >= slen) { if (len < slen) {
buf->bh_curr->b_str[len - slen] = NUL; return;
buf->bh_space += (size_t)slen;
} }
buf->bh_curr->b_str[len - slen] = NUL;
buf->bh_space += (size_t)slen;
} }
/// Add number "n" to buffer "buf". /// Add number "n" to buffer "buf".
@@ -439,24 +441,28 @@ void beep_flush(void)
// This is used for the CTRL-O <.> command in insert mode. // This is used for the CTRL-O <.> command in insert mode.
void ResetRedobuff(void) void ResetRedobuff(void)
{ {
if (!block_redo) { if (block_redo) {
free_buff(&old_redobuff); return;
old_redobuff = redobuff;
redobuff.bh_first.b_next = NULL;
} }
free_buff(&old_redobuff);
old_redobuff = redobuff;
redobuff.bh_first.b_next = NULL;
} }
// Discard the contents of the redo buffer and restore the previous redo // Discard the contents of the redo buffer and restore the previous redo
// buffer. // buffer.
void CancelRedo(void) void CancelRedo(void)
{ {
if (!block_redo) { if (block_redo) {
free_buff(&redobuff); return;
redobuff = old_redobuff;
old_redobuff.bh_first.b_next = NULL;
start_stuff();
while (read_readbuffers(true) != NUL) {}
} }
free_buff(&redobuff);
redobuff = old_redobuff;
old_redobuff.bh_first.b_next = NULL;
start_stuff();
while (read_readbuffers(true) != NUL) {}
} }
/// Save redobuff and old_redobuff to save_redobuff and save_old_redobuff. /// Save redobuff and old_redobuff to save_redobuff and save_old_redobuff.
@@ -470,10 +476,12 @@ void saveRedobuff(save_redo_T *save_redo)
// Make a copy, so that ":normal ." in a function works. // Make a copy, so that ":normal ." in a function works.
char *const s = (char *)get_buffcont(&save_redo->sr_redobuff, false); char *const s = (char *)get_buffcont(&save_redo->sr_redobuff, false);
if (s != NULL) { if (s == NULL) {
add_buff(&redobuff, s, -1L); return;
xfree(s);
} }
add_buff(&redobuff, s, -1L);
xfree(s);
} }
/// Restore redobuff and old_redobuff from save_redobuff and save_old_redobuff. /// Restore redobuff and old_redobuff from save_redobuff and save_old_redobuff.
@@ -811,14 +819,16 @@ void stop_redo_ins(void)
// be impossible to type anything. // be impossible to type anything.
static void init_typebuf(void) static void init_typebuf(void)
{ {
if (typebuf.tb_buf == NULL) { if (typebuf.tb_buf != NULL) {
typebuf.tb_buf = typebuf_init; return;
typebuf.tb_noremap = noremapbuf_init;
typebuf.tb_buflen = TYPELEN_INIT;
typebuf.tb_len = 0;
typebuf.tb_off = MAXMAPLEN + 4;
typebuf.tb_change_cnt = 1;
} }
typebuf.tb_buf = typebuf_init;
typebuf.tb_noremap = noremapbuf_init;
typebuf.tb_buflen = TYPELEN_INIT;
typebuf.tb_len = 0;
typebuf.tb_off = MAXMAPLEN + 4;
typebuf.tb_change_cnt = 1;
} }
/// @return true when keys cannot be remapped. /// @return true when keys cannot be remapped.
@@ -1126,10 +1136,12 @@ static void gotchars(const char_u *chars, size_t len)
/// Only affects recorded characters. /// Only affects recorded characters.
void ungetchars(int len) void ungetchars(int len)
{ {
if (reg_recording != 0) { if (reg_recording == 0) {
delete_buff_tail(&recordbuff, len); return;
last_recorded_len -= (size_t)len;
} }
delete_buff_tail(&recordbuff, len);
last_recorded_len -= (size_t)len;
} }
// Sync undo. Called when typed characters are obtained from the typeahead // Sync undo. Called when typed characters are obtained from the typeahead
@@ -1775,19 +1787,21 @@ void f_getcharstr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{ {
getchar_common(argvars, rettv); getchar_common(argvars, rettv);
if (rettv->v_type == VAR_NUMBER) { if (rettv->v_type != VAR_NUMBER) {
char temp[7]; // mbyte-char: 6, NUL: 1 return;
const varnumber_T n = rettv->vval.v_number;
int i = 0;
if (n != 0) {
i += utf_char2bytes((int)n, (char *)temp);
}
assert(i < 7);
temp[i++] = NUL;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = xstrdup(temp);
} }
char temp[7]; // mbyte-char: 6, NUL: 1
const varnumber_T n = rettv->vval.v_number;
int i = 0;
if (n != 0) {
i += utf_char2bytes((int)n, (char *)temp);
}
assert(i < 7);
temp[i++] = NUL;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = xstrdup(temp);
} }
/// "getcharmod()" function /// "getcharmod()" function