vim-patch:9.0.1245: code is indented more than necessary (#21998)

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

032713f829

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2023-01-26 08:52:21 +08:00
committed by GitHub
parent f15947866c
commit 88e906d165
5 changed files with 225 additions and 212 deletions

View File

@@ -7823,7 +7823,9 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
// MSVC returns NULL for an invalid value of seconds. // MSVC returns NULL for an invalid value of seconds.
if (curtime_ptr == NULL) { if (curtime_ptr == NULL) {
rettv->vval.v_string = xstrdup(_("(Invalid)")); rettv->vval.v_string = xstrdup(_("(Invalid)"));
} else { return;
}
vimconv_T conv; vimconv_T conv;
conv.vc_type = CONV_NONE; conv.vc_type = CONV_NONE;
@@ -7850,7 +7852,6 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
// Release conversion descriptors. // Release conversion descriptors.
convert_setup(&conv, NULL, NULL); convert_setup(&conv, NULL, NULL);
xfree(enc); xfree(enc);
}
} }
/// "strgetchar()" function /// "strgetchar()" function
@@ -8654,6 +8655,7 @@ static void f_timer_pause(typval_T *argvars, typval_T *unused, EvalFuncData fptr
emsg(_(e_number_exp)); emsg(_(e_number_exp));
return; return;
} }
int paused = (bool)tv_get_number(&argvars[1]); int paused = (bool)tv_get_number(&argvars[1]);
timer_T *timer = find_timer_by_nr(tv_get_number(&argvars[0])); timer_T *timer = find_timer_by_nr(tv_get_number(&argvars[0]));
if (timer != NULL) { if (timer != NULL) {

View File

@@ -3208,7 +3208,10 @@ static inline void _nothing_conv_dict_end(typval_T *const tv, dict_T **const dic
/// @param[in,out] tv Value to free. /// @param[in,out] tv Value to free.
void tv_clear(typval_T *const tv) void tv_clear(typval_T *const tv)
{ {
if (tv != NULL && tv->v_type != VAR_UNKNOWN) { if (tv == NULL || tv->v_type == VAR_UNKNOWN) {
return;
}
// WARNING: do not translate the string here, gettext is slow and function // WARNING: do not translate the string here, gettext is slow and function
// is used *very* often. At the current state encode_vim_to_nothing() does // is used *very* often. At the current state encode_vim_to_nothing() does
// not error out and does not use the argument anywhere. // not error out and does not use the argument anywhere.
@@ -3218,7 +3221,6 @@ void tv_clear(typval_T *const tv)
const int evn_ret = encode_vim_to_nothing(NULL, tv, "tv_clear() argument"); const int evn_ret = encode_vim_to_nothing(NULL, tv, "tv_clear() argument");
(void)evn_ret; (void)evn_ret;
assert(evn_ret == OK); assert(evn_ret == OK);
}
} }
//{{{3 Free //{{{3 Free
@@ -3228,7 +3230,10 @@ void tv_clear(typval_T *const tv)
/// @param tv Object to free. /// @param tv Object to free.
void tv_free(typval_T *tv) void tv_free(typval_T *tv)
{ {
if (tv != NULL) { if (tv == NULL) {
return;
}
switch (tv->v_type) { switch (tv->v_type) {
case VAR_PARTIAL: case VAR_PARTIAL:
partial_unref(tv->vval.v_partial); partial_unref(tv->vval.v_partial);
@@ -3256,7 +3261,6 @@ void tv_free(typval_T *tv)
break; break;
} }
xfree(tv); xfree(tv);
}
} }
//{{{3 Copy //{{{3 Copy

View File

@@ -2732,7 +2732,10 @@ static int parse_match(char *lbuf, tagptrs_T *tagp)
tagp->tagline = 0; tagp->tagline = 0;
tagp->command_end = NULL; tagp->command_end = NULL;
if (retval == OK) { if (retval != OK) {
return retval;
}
// Try to find a kind field: "kind:<kind>" or just "<kind>" // Try to find a kind field: "kind:<kind>" or just "<kind>"
p = tagp->command; p = tagp->command;
if (find_extra(&p) == OK) { if (find_extra(&p) == OK) {
@@ -2781,7 +2784,6 @@ static int parse_match(char *lbuf, tagptrs_T *tagp)
MB_PTR_ADV(p)) {} MB_PTR_ADV(p)) {}
tagp->user_data_end = p; tagp->user_data_end = p;
} }
}
return retval; return retval;
} }
@@ -3329,7 +3331,10 @@ int get_tags(list_T *list, char *pat, char *buf_fname)
ret = find_tags(pat, &num_matches, &matches, ret = find_tags(pat, &num_matches, &matches,
TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname); TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname);
if (ret == OK && num_matches > 0) { if (ret != OK || num_matches <= 0) {
return ret;
}
for (i = 0; i < num_matches; i++) { for (i = 0; i < num_matches; i++) {
int parse_result = parse_match(matches[i], &tp); int parse_result = parse_match(matches[i], &tp);
@@ -3408,7 +3413,6 @@ int get_tags(list_T *list, char *pat, char *buf_fname)
xfree(matches[i]); xfree(matches[i]);
} }
xfree(matches); xfree(matches);
}
return ret; return ret;
} }

View File

@@ -77,7 +77,9 @@ static void ga_concat_esc(garray_T *gap, const char *p, int clen)
memmove(buf, p, (size_t)clen); memmove(buf, p, (size_t)clen);
buf[clen] = NUL; buf[clen] = NUL;
ga_concat(gap, buf); ga_concat(gap, buf);
} else { return;
}
switch (*p) { switch (*p) {
case BS: case BS:
ga_concat(gap, "\\b"); break; ga_concat(gap, "\\b"); break;
@@ -102,7 +104,6 @@ static void ga_concat_esc(garray_T *gap, const char *p, int clen)
} }
break; break;
} }
}
} }
/// Append "str" to "gap", escaping unprintable characters. /// Append "str" to "gap", escaping unprintable characters.

View File

@@ -736,7 +736,10 @@ void check_auto_format(bool end_insert)
int c = ' '; int c = ' ';
int cc; int cc;
if (did_add_space) { if (!did_add_space) {
return;
}
cc = gchar_cursor(); cc = gchar_cursor();
if (!WHITECHAR(cc)) { if (!WHITECHAR(cc)) {
// Somehow the space was removed already. // Somehow the space was removed already.
@@ -753,7 +756,6 @@ void check_auto_format(bool end_insert)
did_add_space = false; did_add_space = false;
} }
} }
}
} }
/// Find out textwidth to be used for formatting: /// Find out textwidth to be used for formatting: