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,34 +7823,35 @@ 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;
conv.vc_type = CONV_NONE;
char *enc = enc_locale();
convert_setup(&conv, p_enc, enc);
if (conv.vc_type != CONV_NONE) {
p = string_convert(&conv, p, NULL);
}
char result_buf[256];
if (p == NULL || strftime(result_buf, sizeof(result_buf), p, curtime_ptr) == 0) {
result_buf[0] = NUL;
}
if (conv.vc_type != CONV_NONE) {
xfree(p);
}
convert_setup(&conv, enc, p_enc);
if (conv.vc_type != CONV_NONE) {
rettv->vval.v_string = string_convert(&conv, result_buf, NULL);
} else {
rettv->vval.v_string = xstrdup(result_buf);
}
// Release conversion descriptors.
convert_setup(&conv, NULL, NULL);
xfree(enc);
} }
vimconv_T conv;
conv.vc_type = CONV_NONE;
char *enc = enc_locale();
convert_setup(&conv, p_enc, enc);
if (conv.vc_type != CONV_NONE) {
p = string_convert(&conv, p, NULL);
}
char result_buf[256];
if (p == NULL || strftime(result_buf, sizeof(result_buf), p, curtime_ptr) == 0) {
result_buf[0] = NUL;
}
if (conv.vc_type != CONV_NONE) {
xfree(p);
}
convert_setup(&conv, enc, p_enc);
if (conv.vc_type != CONV_NONE) {
rettv->vval.v_string = string_convert(&conv, result_buf, NULL);
} else {
rettv->vval.v_string = xstrdup(result_buf);
}
// Release conversion descriptors.
convert_setup(&conv, NULL, NULL);
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,17 +3208,19 @@ 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) {
// WARNING: do not translate the string here, gettext is slow and function return;
// is used *very* often. At the current state encode_vim_to_nothing() does
// not error out and does not use the argument anywhere.
//
// If situation changes and this argument will be used, translate it in the
// place where it is used.
const int evn_ret = encode_vim_to_nothing(NULL, tv, "tv_clear() argument");
(void)evn_ret;
assert(evn_ret == OK);
} }
// 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
// not error out and does not use the argument anywhere.
//
// If situation changes and this argument will be used, translate it in the
// place where it is used.
const int evn_ret = encode_vim_to_nothing(NULL, tv, "tv_clear() argument");
(void)evn_ret;
assert(evn_ret == OK);
} }
//{{{3 Free //{{{3 Free
@@ -3228,35 +3230,37 @@ 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) {
switch (tv->v_type) { return;
case VAR_PARTIAL:
partial_unref(tv->vval.v_partial);
break;
case VAR_FUNC:
func_unref(tv->vval.v_string);
FALLTHROUGH;
case VAR_STRING:
xfree(tv->vval.v_string);
break;
case VAR_BLOB:
tv_blob_unref(tv->vval.v_blob);
break;
case VAR_LIST:
tv_list_unref(tv->vval.v_list);
break;
case VAR_DICT:
tv_dict_unref(tv->vval.v_dict);
break;
case VAR_BOOL:
case VAR_SPECIAL:
case VAR_NUMBER:
case VAR_FLOAT:
case VAR_UNKNOWN:
break;
}
xfree(tv);
} }
switch (tv->v_type) {
case VAR_PARTIAL:
partial_unref(tv->vval.v_partial);
break;
case VAR_FUNC:
func_unref(tv->vval.v_string);
FALLTHROUGH;
case VAR_STRING:
xfree(tv->vval.v_string);
break;
case VAR_BLOB:
tv_blob_unref(tv->vval.v_blob);
break;
case VAR_LIST:
tv_list_unref(tv->vval.v_list);
break;
case VAR_DICT:
tv_dict_unref(tv->vval.v_dict);
break;
case VAR_BOOL:
case VAR_SPECIAL:
case VAR_NUMBER:
case VAR_FLOAT:
case VAR_UNKNOWN:
break;
}
xfree(tv);
} }
//{{{3 Copy //{{{3 Copy

View File

@@ -2732,55 +2732,57 @@ 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) {
// Try to find a kind field: "kind:<kind>" or just "<kind>" return retval;
p = tagp->command; }
if (find_extra(&p) == OK) {
tagp->command_end = p;
if (p > tagp->command && p[-1] == '|') {
tagp->command_end = p - 1; // drop trailing bar
}
p += 2; // skip ";\""
if (*p++ == TAB) {
// Accept ASCII alphabetic kind characters and any multi-byte
// character.
while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) {
if (strncmp(p, "kind:", 5) == 0) {
tagp->tagkind = p + 5;
} else if (strncmp(p, "user_data:", 10) == 0) {
tagp->user_data = p + 10;
} else if (strncmp(p, "line:", 5) == 0) {
tagp->tagline = atoi(p + 5);
}
if (tagp->tagkind != NULL && tagp->user_data != NULL) {
break;
}
pc = vim_strchr(p, ':'); // Try to find a kind field: "kind:<kind>" or just "<kind>"
pt = vim_strchr(p, '\t'); p = tagp->command;
if (pc == NULL || (pt != NULL && pc > pt)) { if (find_extra(&p) == OK) {
tagp->tagkind = p; tagp->command_end = p;
} if (p > tagp->command && p[-1] == '|') {
if (pt == NULL) { tagp->command_end = p - 1; // drop trailing bar
break; }
} p += 2; // skip ";\""
p = pt; if (*p++ == TAB) {
MB_PTR_ADV(p); // Accept ASCII alphabetic kind characters and any multi-byte
// character.
while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) {
if (strncmp(p, "kind:", 5) == 0) {
tagp->tagkind = p + 5;
} else if (strncmp(p, "user_data:", 10) == 0) {
tagp->user_data = p + 10;
} else if (strncmp(p, "line:", 5) == 0) {
tagp->tagline = atoi(p + 5);
} }
if (tagp->tagkind != NULL && tagp->user_data != NULL) {
break;
}
pc = vim_strchr(p, ':');
pt = vim_strchr(p, '\t');
if (pc == NULL || (pt != NULL && pc > pt)) {
tagp->tagkind = p;
}
if (pt == NULL) {
break;
}
p = pt;
MB_PTR_ADV(p);
} }
} }
if (tagp->tagkind != NULL) { }
for (p = tagp->tagkind; if (tagp->tagkind != NULL) {
*p && *p != '\t' && *p != '\r' && *p != '\n'; for (p = tagp->tagkind;
MB_PTR_ADV(p)) {} *p && *p != '\t' && *p != '\r' && *p != '\n';
tagp->tagkind_end = p; MB_PTR_ADV(p)) {}
} tagp->tagkind_end = p;
if (tagp->user_data != NULL) { }
for (p = tagp->user_data; if (tagp->user_data != NULL) {
*p && *p != '\t' && *p != '\r' && *p != '\n'; for (p = tagp->user_data;
MB_PTR_ADV(p)) {} *p && *p != '\t' && *p != '\r' && *p != '\n';
tagp->user_data_end = p; MB_PTR_ADV(p)) {}
} tagp->user_data_end = p;
} }
return retval; return retval;
} }
@@ -3329,86 +3331,88 @@ 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) {
for (i = 0; i < num_matches; i++) { return ret;
int parse_result = parse_match(matches[i], &tp); }
// Avoid an unused variable warning in release builds. for (i = 0; i < num_matches; i++) {
(void)parse_result; int parse_result = parse_match(matches[i], &tp);
assert(parse_result == OK);
is_static = test_for_static(&tp); // Avoid an unused variable warning in release builds.
(void)parse_result;
assert(parse_result == OK);
// Skip pseudo-tag lines. is_static = test_for_static(&tp);
if (strncmp(tp.tagname, "!_TAG_", 6) == 0) {
xfree(matches[i]);
continue;
}
dict = tv_dict_alloc(); // Skip pseudo-tag lines.
tv_list_append_dict(list, dict); if (strncmp(tp.tagname, "!_TAG_", 6) == 0) {
xfree(matches[i]);
continue;
}
full_fname = tag_full_fname(&tp); dict = tv_dict_alloc();
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL tv_list_append_dict(list, dict);
|| add_tag_field(dict, "filename", full_fname, NULL) == FAIL
|| add_tag_field(dict, "cmd", tp.command, tp.command_end) == FAIL
|| add_tag_field(dict, "kind", tp.tagkind,
tp.tagkind ? tp.tagkind_end : NULL) == FAIL
|| tv_dict_add_nr(dict, S_LEN("static"), is_static) == FAIL) {
ret = FAIL;
}
xfree(full_fname); full_fname = tag_full_fname(&tp);
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|| add_tag_field(dict, "filename", full_fname, NULL) == FAIL
|| add_tag_field(dict, "cmd", tp.command, tp.command_end) == FAIL
|| add_tag_field(dict, "kind", tp.tagkind,
tp.tagkind ? tp.tagkind_end : NULL) == FAIL
|| tv_dict_add_nr(dict, S_LEN("static"), is_static) == FAIL) {
ret = FAIL;
}
if (tp.command_end != NULL) { xfree(full_fname);
for (char *p = tp.command_end + 3;
*p != NUL && *p != '\n' && *p != '\r';
MB_PTR_ADV(p)) {
if (p == tp.tagkind
|| (p + 5 == tp.tagkind && strncmp(p, "kind:", 5) == 0)) {
// skip "kind:<kind>" and "<kind>"
p = tp.tagkind_end - 1;
} else if (strncmp(p, "file:", 5) == 0) {
// skip "file:" (static tag)
p += 4;
} else if (!ascii_iswhite(*p)) {
char *s, *n;
int len;
// Add extra field as a dict entry. Fields are if (tp.command_end != NULL) {
// separated by Tabs. for (char *p = tp.command_end + 3;
n = p; *p != NUL && *p != '\n' && *p != '\r';
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') { MB_PTR_ADV(p)) {
if (p == tp.tagkind
|| (p + 5 == tp.tagkind && strncmp(p, "kind:", 5) == 0)) {
// skip "kind:<kind>" and "<kind>"
p = tp.tagkind_end - 1;
} else if (strncmp(p, "file:", 5) == 0) {
// skip "file:" (static tag)
p += 4;
} else if (!ascii_iswhite(*p)) {
char *s, *n;
int len;
// Add extra field as a dict entry. Fields are
// separated by Tabs.
n = p;
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') {
p++;
}
len = (int)(p - n);
if (*p == ':' && len > 0) {
s = ++p;
while (*p != NUL && (uint8_t)(*p) >= ' ') {
p++; p++;
} }
len = (int)(p - n); n[len] = NUL;
if (*p == ':' && len > 0) { if (add_tag_field(dict, n, s, p) == FAIL) {
s = ++p; ret = FAIL;
while (*p != NUL && (uint8_t)(*p) >= ' ') {
p++;
}
n[len] = NUL;
if (add_tag_field(dict, n, s, p) == FAIL) {
ret = FAIL;
}
n[len] = ':';
} else {
// Skip field without colon.
while (*p != NUL && (uint8_t)(*p) >= ' ') {
p++;
}
} }
if (*p == NUL) { n[len] = ':';
break; } else {
// Skip field without colon.
while (*p != NUL && (uint8_t)(*p) >= ' ') {
p++;
} }
} }
if (*p == NUL) {
break;
}
} }
} }
xfree(matches[i]);
} }
xfree(matches);
xfree(matches[i]);
} }
xfree(matches);
return ret; return ret;
} }

View File

@@ -77,31 +77,32 @@ 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) { }
case BS:
ga_concat(gap, "\\b"); break; switch (*p) {
case ESC: case BS:
ga_concat(gap, "\\e"); break; ga_concat(gap, "\\b"); break;
case FF: case ESC:
ga_concat(gap, "\\f"); break; ga_concat(gap, "\\e"); break;
case NL: case FF:
ga_concat(gap, "\\n"); break; ga_concat(gap, "\\f"); break;
case TAB: case NL:
ga_concat(gap, "\\t"); break; ga_concat(gap, "\\n"); break;
case CAR: case TAB:
ga_concat(gap, "\\r"); break; ga_concat(gap, "\\t"); break;
case '\\': case CAR:
ga_concat(gap, "\\\\"); break; ga_concat(gap, "\\r"); break;
default: case '\\':
if ((uint8_t)(*p) < ' ' || *p == 0x7f) { ga_concat(gap, "\\\\"); break;
vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p); default:
ga_concat(gap, buf); if ((uint8_t)(*p) < ' ' || *p == 0x7f) {
} else { vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p);
ga_append(gap, (uint8_t)(*p)); ga_concat(gap, buf);
} } else {
break; ga_append(gap, (uint8_t)(*p));
} }
break;
} }
} }

View File

@@ -736,22 +736,24 @@ void check_auto_format(bool end_insert)
int c = ' '; int c = ' ';
int cc; int cc;
if (did_add_space) { if (!did_add_space) {
cc = gchar_cursor(); return;
if (!WHITECHAR(cc)) { }
// Somehow the space was removed already.
cc = gchar_cursor();
if (!WHITECHAR(cc)) {
// Somehow the space was removed already.
did_add_space = false;
} else {
if (!end_insert) {
inc_cursor();
c = gchar_cursor();
dec_cursor();
}
if (c != NUL) {
// The space is no longer at the end of the line, delete it.
del_char(false);
did_add_space = false; did_add_space = false;
} else {
if (!end_insert) {
inc_cursor();
c = gchar_cursor();
dec_cursor();
}
if (c != NUL) {
// The space is no longer at the end of the line, delete it.
del_char(false);
did_add_space = false;
}
} }
} }
} }