Skip to content

Commit 032713f

Browse files
yegappanbrammool
authored andcommitted
patch 9.0.1245: code is indented more than necessary
Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11879)
1 parent 0f843ef commit 032713f

9 files changed

Lines changed: 919 additions & 913 deletions

File tree

src/tag.c

Lines changed: 128 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,16 +3263,16 @@ static garray_T tag_fnames = GA_EMPTY;
32633263
static void
32643264
found_tagfile_cb(char_u *fname, void *cookie UNUSED)
32653265
{
3266-
if (ga_grow(&tag_fnames, 1) == OK)
3267-
{
3268-
char_u *tag_fname = vim_strsave(fname);
3266+
if (ga_grow(&tag_fnames, 1) == FAIL)
3267+
return;
3268+
3269+
char_u *tag_fname = vim_strsave(fname);
32693270

32703271
#ifdef BACKSLASH_IN_FILENAME
3271-
slash_adjust(tag_fname);
3272+
slash_adjust(tag_fname);
32723273
#endif
3273-
simplify_filename(tag_fname);
3274-
((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = tag_fname;
3275-
}
3274+
simplify_filename(tag_fname);
3275+
((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = tag_fname;
32763276
}
32773277

32783278
#if defined(EXITFREE) || defined(PROTO)
@@ -3587,54 +3587,54 @@ parse_match(
35873587
tagp->tagline = 0;
35883588
tagp->command_end = NULL;
35893589

3590-
if (retval == OK)
3590+
if (retval != OK)
3591+
return retval;
3592+
3593+
// Try to find a kind field: "kind:<kind>" or just "<kind>"
3594+
p = tagp->command;
3595+
if (find_extra(&p) == OK)
35913596
{
3592-
// Try to find a kind field: "kind:<kind>" or just "<kind>"
3593-
p = tagp->command;
3594-
if (find_extra(&p) == OK)
3595-
{
3596-
if (p > tagp->command && p[-1] == '|')
3597-
tagp->command_end = p - 1; // drop trailing bar
3598-
else
3599-
tagp->command_end = p;
3600-
p += 2; // skip ";\""
3601-
if (*p++ == TAB)
3602-
// Accept ASCII alphabetic kind characters and any multi-byte
3603-
// character.
3604-
while (ASCII_ISALPHA(*p) || mb_ptr2len(p) > 1)
3605-
{
3606-
if (STRNCMP(p, "kind:", 5) == 0)
3607-
tagp->tagkind = p + 5;
3608-
else if (STRNCMP(p, "user_data:", 10) == 0)
3609-
tagp->user_data = p + 10;
3610-
else if (STRNCMP(p, "line:", 5) == 0)
3611-
tagp->tagline = atoi((char *)p + 5);
3612-
if (tagp->tagkind != NULL && tagp->user_data != NULL)
3613-
break;
3614-
pc = vim_strchr(p, ':');
3615-
pt = vim_strchr(p, '\t');
3616-
if (pc == NULL || (pt != NULL && pc > pt))
3617-
tagp->tagkind = p;
3618-
if (pt == NULL)
3619-
break;
3620-
p = pt;
3621-
MB_PTR_ADV(p);
3622-
}
3623-
}
3624-
if (tagp->tagkind != NULL)
3625-
{
3626-
for (p = tagp->tagkind;
3627-
*p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p))
3628-
;
3629-
tagp->tagkind_end = p;
3630-
}
3631-
if (tagp->user_data != NULL)
3632-
{
3633-
for (p = tagp->user_data;
3634-
*p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p))
3635-
;
3636-
tagp->user_data_end = p;
3637-
}
3597+
if (p > tagp->command && p[-1] == '|')
3598+
tagp->command_end = p - 1; // drop trailing bar
3599+
else
3600+
tagp->command_end = p;
3601+
p += 2; // skip ";\""
3602+
if (*p++ == TAB)
3603+
// Accept ASCII alphabetic kind characters and any multi-byte
3604+
// character.
3605+
while (ASCII_ISALPHA(*p) || mb_ptr2len(p) > 1)
3606+
{
3607+
if (STRNCMP(p, "kind:", 5) == 0)
3608+
tagp->tagkind = p + 5;
3609+
else if (STRNCMP(p, "user_data:", 10) == 0)
3610+
tagp->user_data = p + 10;
3611+
else if (STRNCMP(p, "line:", 5) == 0)
3612+
tagp->tagline = atoi((char *)p + 5);
3613+
if (tagp->tagkind != NULL && tagp->user_data != NULL)
3614+
break;
3615+
pc = vim_strchr(p, ':');
3616+
pt = vim_strchr(p, '\t');
3617+
if (pc == NULL || (pt != NULL && pc > pt))
3618+
tagp->tagkind = p;
3619+
if (pt == NULL)
3620+
break;
3621+
p = pt;
3622+
MB_PTR_ADV(p);
3623+
}
3624+
}
3625+
if (tagp->tagkind != NULL)
3626+
{
3627+
for (p = tagp->tagkind;
3628+
*p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p))
3629+
;
3630+
tagp->tagkind_end = p;
3631+
}
3632+
if (tagp->user_data != NULL)
3633+
{
3634+
for (p = tagp->user_data;
3635+
*p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p))
3636+
;
3637+
tagp->user_data_end = p;
36383638
}
36393639
return retval;
36403640
}
@@ -4372,94 +4372,94 @@ get_tags(list_T *list, char_u *pat, char_u *buf_fname)
43724372

43734373
ret = find_tags(pat, &num_matches, &matches,
43744374
TAG_REGEXP | TAG_NOIC, (int)MAXCOL, buf_fname);
4375-
if (ret == OK && num_matches > 0)
4375+
if (ret != OK || num_matches <= 0)
4376+
return ret;
4377+
4378+
for (i = 0; i < num_matches; ++i)
43764379
{
4377-
for (i = 0; i < num_matches; ++i)
4380+
if (parse_match(matches[i], &tp) == FAIL)
43784381
{
4379-
if (parse_match(matches[i], &tp) == FAIL)
4380-
{
4381-
vim_free(matches[i]);
4382-
continue;
4383-
}
4382+
vim_free(matches[i]);
4383+
continue;
4384+
}
43844385

4385-
is_static = test_for_static(&tp);
4386+
is_static = test_for_static(&tp);
43864387

4387-
// Skip pseudo-tag lines.
4388-
if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0)
4389-
{
4390-
vim_free(matches[i]);
4391-
continue;
4392-
}
4388+
// Skip pseudo-tag lines.
4389+
if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0)
4390+
{
4391+
vim_free(matches[i]);
4392+
continue;
4393+
}
43934394

4394-
if ((dict = dict_alloc()) == NULL)
4395-
{
4396-
ret = FAIL;
4397-
vim_free(matches[i]);
4398-
break;
4399-
}
4400-
if (list_append_dict(list, dict) == FAIL)
4401-
ret = FAIL;
4402-
4403-
full_fname = tag_full_fname(&tp);
4404-
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
4405-
|| add_tag_field(dict, "filename", full_fname,
4406-
NULL) == FAIL
4407-
|| add_tag_field(dict, "cmd", tp.command,
4408-
tp.command_end) == FAIL
4409-
|| add_tag_field(dict, "kind", tp.tagkind,
4410-
tp.tagkind_end) == FAIL
4411-
|| dict_add_number(dict, "static", is_static) == FAIL)
4412-
ret = FAIL;
4413-
4414-
vim_free(full_fname);
4415-
4416-
if (tp.command_end != NULL)
4395+
if ((dict = dict_alloc()) == NULL)
4396+
{
4397+
ret = FAIL;
4398+
vim_free(matches[i]);
4399+
break;
4400+
}
4401+
if (list_append_dict(list, dict) == FAIL)
4402+
ret = FAIL;
4403+
4404+
full_fname = tag_full_fname(&tp);
4405+
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
4406+
|| add_tag_field(dict, "filename", full_fname,
4407+
NULL) == FAIL
4408+
|| add_tag_field(dict, "cmd", tp.command,
4409+
tp.command_end) == FAIL
4410+
|| add_tag_field(dict, "kind", tp.tagkind,
4411+
tp.tagkind_end) == FAIL
4412+
|| dict_add_number(dict, "static", is_static) == FAIL)
4413+
ret = FAIL;
4414+
4415+
vim_free(full_fname);
4416+
4417+
if (tp.command_end != NULL)
4418+
{
4419+
for (p = tp.command_end + 3;
4420+
*p != NUL && *p != '\n' && *p != '\r'; MB_PTR_ADV(p))
44174421
{
4418-
for (p = tp.command_end + 3;
4419-
*p != NUL && *p != '\n' && *p != '\r'; MB_PTR_ADV(p))
4422+
if (p == tp.tagkind || (p + 5 == tp.tagkind
4423+
&& STRNCMP(p, "kind:", 5) == 0))
4424+
// skip "kind:<kind>" and "<kind>"
4425+
p = tp.tagkind_end - 1;
4426+
else if (STRNCMP(p, "file:", 5) == 0)
4427+
// skip "file:" (static tag)
4428+
p += 4;
4429+
else if (!VIM_ISWHITE(*p))
44204430
{
4421-
if (p == tp.tagkind || (p + 5 == tp.tagkind
4422-
&& STRNCMP(p, "kind:", 5) == 0))
4423-
// skip "kind:<kind>" and "<kind>"
4424-
p = tp.tagkind_end - 1;
4425-
else if (STRNCMP(p, "file:", 5) == 0)
4426-
// skip "file:" (static tag)
4427-
p += 4;
4428-
else if (!VIM_ISWHITE(*p))
4431+
char_u *s, *n;
4432+
int len;
4433+
4434+
// Add extra field as a dict entry. Fields are
4435+
// separated by Tabs.
4436+
n = p;
4437+
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':')
4438+
++p;
4439+
len = (int)(p - n);
4440+
if (*p == ':' && len > 0)
44294441
{
4430-
char_u *s, *n;
4431-
int len;
4432-
4433-
// Add extra field as a dict entry. Fields are
4434-
// separated by Tabs.
4435-
n = p;
4436-
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':')
4442+
s = ++p;
4443+
while (*p != NUL && *p >= ' ')
44374444
++p;
4438-
len = (int)(p - n);
4439-
if (*p == ':' && len > 0)
4440-
{
4441-
s = ++p;
4442-
while (*p != NUL && *p >= ' ')
4443-
++p;
4444-
n[len] = NUL;
4445-
if (add_tag_field(dict, (char *)n, s, p) == FAIL)
4446-
ret = FAIL;
4447-
n[len] = ':';
4448-
}
4449-
else
4450-
// Skip field without colon.
4451-
while (*p != NUL && *p >= ' ')
4452-
++p;
4453-
if (*p == NUL)
4454-
break;
4445+
n[len] = NUL;
4446+
if (add_tag_field(dict, (char *)n, s, p) == FAIL)
4447+
ret = FAIL;
4448+
n[len] = ':';
44554449
}
4450+
else
4451+
// Skip field without colon.
4452+
while (*p != NUL && *p >= ' ')
4453+
++p;
4454+
if (*p == NUL)
4455+
break;
44564456
}
44574457
}
4458-
4459-
vim_free(matches[i]);
44604458
}
4461-
vim_free(matches);
4459+
4460+
vim_free(matches[i]);
44624461
}
4462+
vim_free(matches);
44634463
return ret;
44644464
}
44654465

0 commit comments

Comments
 (0)