vim-patch:partial:9.0.1196: code is indented more than necessary (#21796)

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

e857598896

Partial port as this depends on some previous eval and 'smoothscroll'
patches.

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq 2023-01-14 21:36:15 +08:00 committed by GitHub
parent d549734fb4
commit 2065ce877e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 173 additions and 142 deletions

View File

@ -326,11 +326,13 @@ void tv_list_free_list(list_T *const l)
void tv_list_free(list_T *const l) void tv_list_free(list_T *const l)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (!tv_in_free_unref_items) { if (tv_in_free_unref_items) {
return;
}
tv_list_free_contents(l); tv_list_free_contents(l);
tv_list_free_list(l); tv_list_free_list(l);
} }
}
/// Unreference a list /// Unreference a list
/// ///

View File

@ -403,7 +403,10 @@ int name_to_mod_mask(int c)
int simplify_key(const int key, int *modifiers) int simplify_key(const int key, int *modifiers)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
if (*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)) { if (!(*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT))) {
return key;
}
// TAB is a special case. // TAB is a special case.
if (key == TAB && (*modifiers & MOD_MASK_SHIFT)) { if (key == TAB && (*modifiers & MOD_MASK_SHIFT)) {
*modifiers &= ~MOD_MASK_SHIFT; *modifiers &= ~MOD_MASK_SHIFT;
@ -420,7 +423,6 @@ int simplify_key(const int key, int *modifiers)
modifier_keys_table[i + 2]); modifier_keys_table[i + 2]);
} }
} }
}
return key; return key;
} }

View File

@ -317,24 +317,27 @@ static char **find_locales(void)
static void init_locales(void) static void init_locales(void)
{ {
# ifndef MSWIN # ifndef MSWIN
if (!did_init_locales) { if (did_init_locales) {
return;
}
did_init_locales = true; did_init_locales = true;
locales = find_locales(); locales = find_locales();
}
# endif # endif
} }
# if defined(EXITFREE) # if defined(EXITFREE)
void free_locales(void) void free_locales(void)
{ {
int i; if (locales == NULL) {
if (locales != NULL) { return;
for (i = 0; locales[i] != NULL; i++) { }
for (int i = 0; locales[i] != NULL; i++) {
xfree(locales[i]); xfree(locales[i]);
} }
XFREE_CLEAR(locales); XFREE_CLEAR(locales);
} }
}
# endif # endif
/// Function given to ExpandGeneric() to obtain the possible arguments of the /// Function given to ExpandGeneric() to obtain the possible arguments of the

View File

@ -1828,7 +1828,10 @@ static void exe_pre_commands(mparm_T *parmp)
int cnt = parmp->n_pre_commands; int cnt = parmp->n_pre_commands;
int i; int i;
if (cnt > 0) { if (cnt <= 0) {
return;
}
curwin->w_cursor.lnum = 0; // just in case.. curwin->w_cursor.lnum = 0; // just in case..
estack_push(ETYPE_ARGS, _("pre-vimrc command line"), 0); estack_push(ETYPE_ARGS, _("pre-vimrc command line"), 0);
current_sctx.sc_sid = SID_CMDARG; current_sctx.sc_sid = SID_CMDARG;
@ -1839,7 +1842,6 @@ static void exe_pre_commands(mparm_T *parmp)
current_sctx.sc_sid = 0; current_sctx.sc_sid = 0;
TIME_MSG("--cmd commands"); TIME_MSG("--cmd commands");
} }
}
// Execute "+", "-c" and "-S" arguments. // Execute "+", "-c" and "-S" arguments.
static void exe_commands(mparm_T *parmp) static void exe_commands(mparm_T *parmp)
@ -2079,7 +2081,10 @@ static int execute_env(char *env)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
const char *initstr = os_getenv(env); const char *initstr = os_getenv(env);
if (initstr != NULL) { if (initstr == NULL) {
return FAIL;
}
estack_push(ETYPE_ENV, env, 0); estack_push(ETYPE_ENV, env, 0);
const sctx_T save_current_sctx = current_sctx; const sctx_T save_current_sctx = current_sctx;
current_sctx.sc_sid = SID_ENV; current_sctx.sc_sid = SID_ENV;
@ -2091,8 +2096,6 @@ static int execute_env(char *env)
current_sctx = save_current_sctx; current_sctx = save_current_sctx;
return OK; return OK;
} }
return FAIL;
}
/// Prints the following then exits: /// Prints the following then exits:
/// - An error message `errstr` /// - An error message `errstr`

View File

@ -653,7 +653,10 @@ fmark_T *getnextmark(pos_T *startpos, int dir, int begin_line)
// until the mark is used to avoid a long startup delay. // until the mark is used to avoid a long startup delay.
static void fname2fnum(xfmark_T *fm) static void fname2fnum(xfmark_T *fm)
{ {
if (fm->fname != NULL) { if (fm->fname == NULL) {
return;
}
// First expand "~/" in the file name to the home directory. // First expand "~/" in the file name to the home directory.
// Don't expand the whole name, it may contain other '~' chars. // Don't expand the whole name, it may contain other '~' chars.
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
@ -676,7 +679,6 @@ static void fname2fnum(xfmark_T *fm)
// buflist_new() will call fmarks_check_names() // buflist_new() will call fmarks_check_names()
(void)buflist_new(NameBuff, p, (linenr_T)1, 0); (void)buflist_new(NameBuff, p, (linenr_T)1, 0);
} }
}
// Check all file marks for a name that matches the file name in buf. // Check all file marks for a name that matches the file name in buf.
// May replace the name with an fnum. // May replace the name with an fnum.

View File

@ -880,13 +880,15 @@ static int matchadd_dict_arg(typval_T *tv, const char **conceal_char, win_T **wi
*conceal_char = tv_get_string(&di->di_tv); *conceal_char = tv_get_string(&di->di_tv);
} }
if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("window"))) != NULL) { if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("window"))) == NULL) {
return OK;
}
*win = find_win_by_nr_or_id(&di->di_tv); *win = find_win_by_nr_or_id(&di->di_tv);
if (*win == NULL) { if (*win == NULL) {
emsg(_(e_invalwindow)); emsg(_(e_invalwindow));
return FAIL; return FAIL;
} }
}
return OK; return OK;
} }

View File

@ -767,12 +767,14 @@ void mf_set_fnames(memfile_T *mfp, char *fname)
/// Used before doing a :cd /// Used before doing a :cd
void mf_fullname(memfile_T *mfp) void mf_fullname(memfile_T *mfp)
{ {
if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) { if (mfp == NULL || mfp->mf_fname == NULL || mfp->mf_ffname == NULL) {
return;
}
xfree(mfp->mf_fname); xfree(mfp->mf_fname);
mfp->mf_fname = mfp->mf_ffname; mfp->mf_fname = mfp->mf_ffname;
mfp->mf_ffname = NULL; mfp->mf_ffname = NULL;
} }
}
/// Return true if there are any translations pending for memfile. /// Return true if there are any translations pending for memfile.
bool mf_need_trans(memfile_T *mfp) bool mf_need_trans(memfile_T *mfp)

View File

@ -1377,7 +1377,10 @@ char *make_percent_swname(const char *dir, const char *name)
{ {
char *d = NULL; char *d = NULL;
char *f = fix_fname(name != NULL ? name : ""); char *f = fix_fname(name != NULL ? name : "");
if (f != NULL) { if (f == NULL) {
return NULL;
}
char *s = xstrdup(f); char *s = xstrdup(f);
for (d = s; *d != NUL; MB_PTR_ADV(d)) { for (d = s; *d != NUL; MB_PTR_ADV(d)) {
if (vim_ispathsep(*d)) { if (vim_ispathsep(*d)) {
@ -1387,7 +1390,6 @@ char *make_percent_swname(const char *dir, const char *name)
d = concat_fnames(dir, s, true); d = concat_fnames(dir, s, true);
xfree(s); xfree(s);
xfree(f); xfree(f);
}
return d; return d;
} }

View File

@ -1449,9 +1449,11 @@ void show_popupmenu(void)
} }
// Only show a popup when it is defined and has entries // Only show a popup when it is defined and has entries
if (menu != NULL && menu->children != NULL) { if (menu == NULL || menu->children == NULL) {
pum_show_popupmenu(menu); return;
} }
pum_show_popupmenu(menu);
} }
/// Execute "menu". Use by ":emenu" and the window toolbar. /// Execute "menu". Use by ":emenu" and the window toolbar.

View File

@ -606,30 +606,40 @@ void validate_virtcol(void)
void validate_virtcol_win(win_T *wp) void validate_virtcol_win(win_T *wp)
{ {
check_cursor_moved(wp); check_cursor_moved(wp);
if (!(wp->w_valid & VALID_VIRTCOL)) {
if (wp->w_valid & VALID_VIRTCOL) {
return;
}
getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL); getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
redraw_for_cursorcolumn(wp); redraw_for_cursorcolumn(wp);
wp->w_valid |= VALID_VIRTCOL; wp->w_valid |= VALID_VIRTCOL;
} }
}
// Validate curwin->w_cline_height only. // Validate curwin->w_cline_height only.
void validate_cheight(void) void validate_cheight(void)
{ {
check_cursor_moved(curwin); check_cursor_moved(curwin);
if (!(curwin->w_valid & VALID_CHEIGHT)) {
if (curwin->w_valid & VALID_CHEIGHT) {
return;
}
curwin->w_cline_height = plines_win_full(curwin, curwin->w_cursor.lnum, curwin->w_cline_height = plines_win_full(curwin, curwin->w_cursor.lnum,
NULL, &curwin->w_cline_folded, NULL, &curwin->w_cline_folded,
true); true);
curwin->w_valid |= VALID_CHEIGHT; curwin->w_valid |= VALID_CHEIGHT;
} }
}
// Validate w_wcol and w_virtcol only. // Validate w_wcol and w_virtcol only.
void validate_cursor_col(void) void validate_cursor_col(void)
{ {
validate_virtcol(); validate_virtcol();
if (!(curwin->w_valid & VALID_WCOL)) {
if (curwin->w_valid & VALID_WCOL) {
return;
}
colnr_T col = curwin->w_virtcol; colnr_T col = curwin->w_virtcol;
colnr_T off = curwin_col_off(); colnr_T off = curwin_col_off();
col += off; col += off;
@ -650,7 +660,6 @@ void validate_cursor_col(void)
curwin->w_valid |= VALID_WCOL; curwin->w_valid |= VALID_WCOL;
} }
}
// Compute offset of a window, occupied by absolute or relative line number, // Compute offset of a window, occupied by absolute or relative line number,
// fold column and sign column (these don't move when scrolling horizontally). // fold column and sign column (these don't move when scrolling horizontally).

View File

@ -292,7 +292,10 @@ void vim_beep(unsigned val)
{ {
called_vim_beep = true; called_vim_beep = true;
if (emsg_silent == 0 && !in_assert_fails) { if (emsg_silent != 0 || in_assert_fails) {
return;
}
if (!((bo_flags & val) || (bo_flags & BO_ALL))) { if (!((bo_flags & val) || (bo_flags & BO_ALL))) {
static int beeps = 0; static int beeps = 0;
static uint64_t start_time = 0; static uint64_t start_time = 0;
@ -321,7 +324,6 @@ void vim_beep(unsigned val)
msg_attr(_("Beep!"), HL_ATTR(HLF_W)); msg_attr(_("Beep!"), HL_ATTR(HLF_W));
} }
} }
}
void ui_attach_impl(UI *ui, uint64_t chanid) void ui_attach_impl(UI *ui, uint64_t chanid)
{ {