Skip to content

Commit

Permalink
patch 9.0.1166: code is indented more than necessary
Browse files Browse the repository at this point in the history
Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes #11792)
  • Loading branch information
yegappan authored and brammool committed Jan 9, 2023
1 parent 765d82a commit 1cfb14a
Show file tree
Hide file tree
Showing 22 changed files with 907 additions and 881 deletions.
24 changes: 12 additions & 12 deletions src/autocmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,18 +1063,18 @@ au_get_grouparg(char_u **argp)

for (p = arg; *p && !VIM_ISWHITE(*p) && *p != '|'; ++p)
;
if (p > arg)
{
group_name = vim_strnsave(arg, p - arg);
if (group_name == NULL) // out of memory
return AUGROUP_ERROR;
group = au_find_group(group_name);
if (group == AUGROUP_ERROR)
group = AUGROUP_ALL; // no match, use all groups
else
*argp = skipwhite(p); // match, skip over group name
vim_free(group_name);
}
if (p <= arg)
return AUGROUP_ALL;

group_name = vim_strnsave(arg, p - arg);
if (group_name == NULL) // out of memory
return AUGROUP_ERROR;
group = au_find_group(group_name);
if (group == AUGROUP_ERROR)
group = AUGROUP_ALL; // no match, use all groups
else
*argp = skipwhite(p); // match, skip over group name
vim_free(group_name);
return group;
}

Expand Down
114 changes: 56 additions & 58 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,34 +357,34 @@ open_buffer(
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
#endif

if (retval == OK)
if (retval != OK)
return retval;

// The autocommands may have changed the current buffer. Apply the
// modelines to the correct buffer, if it still exists and is loaded.
if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL)
{
// The autocommands may have changed the current buffer. Apply the
// modelines to the correct buffer, if it still exists and is loaded.
if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL)
{
aco_save_T aco;
aco_save_T aco;

// Go to the buffer that was opened, make sure it is in a window.
// If not then skip it.
aucmd_prepbuf(&aco, old_curbuf.br_buf);
if (curbuf == old_curbuf.br_buf)
{
do_modelines(0);
curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
// Go to the buffer that was opened, make sure it is in a window.
// If not then skip it.
aucmd_prepbuf(&aco, old_curbuf.br_buf);
if (curbuf == old_curbuf.br_buf)
{
do_modelines(0);
curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);

if ((flags & READ_NOWINENTER) == 0)
if ((flags & READ_NOWINENTER) == 0)
#ifdef FEAT_EVAL
apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL,
FALSE, curbuf, &retval);
apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL,
FALSE, curbuf, &retval);
#else
apply_autocmds(EVENT_BUFWINENTER, NULL, NULL,
FALSE, curbuf);
apply_autocmds(EVENT_BUFWINENTER, NULL, NULL,
FALSE, curbuf);
#endif

// restore curwin/curbuf and a few other things
aucmd_restbuf(&aco);
}
// restore curwin/curbuf and a few other things
aucmd_restbuf(&aco);
}
}

Expand Down Expand Up @@ -1761,7 +1761,6 @@ do_bufdel(
}
}


return errormsg;
}

Expand Down Expand Up @@ -3019,20 +3018,20 @@ fname_match(
char_u *p;

// extra check for valid arguments
if (name != NULL && rmp->regprog != NULL)
if (name == NULL || rmp->regprog == NULL)
return NULL;

// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
if (vim_regexec(rmp, name, (colnr_T)0))
match = name;
else if (rmp->regprog != NULL)
{
// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
if (vim_regexec(rmp, name, (colnr_T)0))
// Replace $(HOME) with '~' and try matching again.
p = home_replace_save(NULL, name);
if (p != NULL && vim_regexec(rmp, p, (colnr_T)0))
match = name;
else if (rmp->regprog != NULL)
{
// Replace $(HOME) with '~' and try matching again.
p = home_replace_save(NULL, name);
if (p != NULL && vim_regexec(rmp, p, (colnr_T)0))
match = name;
vim_free(p);
}
vim_free(p);
}

return match;
Expand Down Expand Up @@ -3160,16 +3159,15 @@ wininfo_other_tab_diff(wininfo_T *wip)
{
win_T *wp;

if (wip->wi_opt.wo_diff)
{
FOR_ALL_WINDOWS(wp)
// return FALSE when it's a window in the current tab page, thus
// the buffer was in diff mode here
if (wip->wi_win == wp)
return FALSE;
return TRUE;
}
return FALSE;
if (!wip->wi_opt.wo_diff)
return FALSE;

FOR_ALL_WINDOWS(wp)
// return FALSE when it's a window in the current tab page, thus
// the buffer was in diff mode here
if (wip->wi_win == wp)
return FALSE;
return TRUE;
}
#endif

Expand Down Expand Up @@ -3198,27 +3196,27 @@ find_wininfo(
&& (!need_options || wip->wi_optset))
break;

if (wip != NULL)
return wip;

// If no wininfo for curwin, use the first in the list (that doesn't have
// 'diff' set and is in another tab page).
// If "need_options" is TRUE skip entries that don't have options set,
// unless the window is editing "buf", so we can copy from the window
// itself.
if (wip == NULL)
{
#ifdef FEAT_DIFF
if (skip_diff_buffer)
{
FOR_ALL_BUF_WININFO(buf, wip)
if (!wininfo_other_tab_diff(wip)
&& (!need_options || wip->wi_optset
|| (wip->wi_win != NULL
&& wip->wi_win->w_buffer == buf)))
break;
}
else
#endif
wip = buf->b_wininfo;
if (skip_diff_buffer)
{
FOR_ALL_BUF_WININFO(buf, wip)
if (!wininfo_other_tab_diff(wip)
&& (!need_options || wip->wi_optset
|| (wip->wi_win != NULL
&& wip->wi_win->w_buffer == buf)))
break;
}
else
#endif
wip = buf->b_wininfo;
return wip;
}

Expand Down
29 changes: 15 additions & 14 deletions src/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,25 @@ transstr(char_u *s)
}
else
res = alloc(vim_strsize(s) + 1);
if (res != NULL)

if (res == NULL)
return NULL;

*res = NUL;
p = s;
while (*p != NUL)
{
*res = NUL;
p = s;
while (*p != NUL)
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
{
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
{
c = (*mb_ptr2char)(p);
if (vim_isprintc(c))
STRNCAT(res, p, l); // append printable multi-byte char
else
transchar_hex(res + STRLEN(res), c);
p += l;
}
c = (*mb_ptr2char)(p);
if (vim_isprintc(c))
STRNCAT(res, p, l); // append printable multi-byte char
else
STRCAT(res, transchar_byte(*p++));
transchar_hex(res + STRLEN(res), c);
p += l;
}
else
STRCAT(res, transchar_byte(*p++));
}
return res;
}
Expand Down
107 changes: 53 additions & 54 deletions src/cindent.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ cin_is_cinword(char_u *line)

cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1;
cinw_buf = alloc(cinw_len);
if (cinw_buf != NULL)
if (cinw_buf == NULL)
return FALSE;

line = skipwhite(line);
for (cinw = curbuf->b_p_cinw; *cinw; )
{
line = skipwhite(line);
for (cinw = curbuf->b_p_cinw; *cinw; )
len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
if (STRNCMP(line, cinw_buf, len) == 0
&& (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1])))
{
len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
if (STRNCMP(line, cinw_buf, len) == 0
&& (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1])))
{
retval = TRUE;
break;
}
retval = TRUE;
break;
}
vim_free(cinw_buf);
}
vim_free(cinw_buf);
return retval;
}

Expand Down Expand Up @@ -644,43 +644,42 @@ cin_islabel(void) // XXX
if (cin_isscopedecl(s))
return FALSE;

if (cin_islabel_skip(&s))
{
// Only accept a label if the previous line is terminated or is a case
// label.
pos_T cursor_save;
pos_T *trypos;
char_u *line;
if (!cin_islabel_skip(&s))
return FALSE;

cursor_save = curwin->w_cursor;
while (curwin->w_cursor.lnum > 1)
{
--curwin->w_cursor.lnum;
// Only accept a label if the previous line is terminated or is a case
// label.
pos_T cursor_save;
pos_T *trypos;
char_u *line;

// If we're in a comment or raw string now, skip to the start of
// it.
curwin->w_cursor.col = 0;
if ((trypos = ind_find_start_CORS(NULL)) != NULL) // XXX
curwin->w_cursor = *trypos;
cursor_save = curwin->w_cursor;
while (curwin->w_cursor.lnum > 1)
{
--curwin->w_cursor.lnum;

line = ml_get_curline();
if (cin_ispreproc(line)) // ignore #defines, #if, etc.
continue;
if (*(line = cin_skipcomment(line)) == NUL)
continue;
// If we're in a comment or raw string now, skip to the start of
// it.
curwin->w_cursor.col = 0;
if ((trypos = ind_find_start_CORS(NULL)) != NULL) // XXX
curwin->w_cursor = *trypos;

line = ml_get_curline();
if (cin_ispreproc(line)) // ignore #defines, #if, etc.
continue;
if (*(line = cin_skipcomment(line)) == NUL)
continue;

curwin->w_cursor = cursor_save;
if (cin_isterminated(line, TRUE, FALSE)
|| cin_isscopedecl(line)
|| cin_iscase(line, TRUE)
|| (cin_islabel_skip(&line) && cin_nocode(line)))
return TRUE;
return FALSE;
}
curwin->w_cursor = cursor_save;
return TRUE; // label at start of file???
if (cin_isterminated(line, TRUE, FALSE)
|| cin_isscopedecl(line)
|| cin_iscase(line, TRUE)
|| (cin_islabel_skip(&line) && cin_nocode(line)))
return TRUE;
return FALSE;
}
return FALSE;
curwin->w_cursor = cursor_save;
return TRUE; // label at start of file???
}

/*
Expand Down Expand Up @@ -1688,18 +1687,18 @@ find_match_paren_after_brace (int ind_maxparen) // XXX
{
pos_T *trypos = find_match_paren(ind_maxparen);

if (trypos != NULL)
{
pos_T *tryposBrace = find_start_brace();

// If both an unmatched '(' and '{' is found. Ignore the '('
// position if the '{' is further down.
if (tryposBrace != NULL
&& (trypos->lnum != tryposBrace->lnum
? trypos->lnum < tryposBrace->lnum
: trypos->col < tryposBrace->col))
trypos = NULL;
}
if (trypos == NULL)
return NULL;

pos_T *tryposBrace = find_start_brace();

// If both an unmatched '(' and '{' is found. Ignore the '('
// position if the '{' is further down.
if (tryposBrace != NULL
&& (trypos->lnum != tryposBrace->lnum
? trypos->lnum < tryposBrace->lnum
: trypos->col < tryposBrace->col))
trypos = NULL;
return trypos;
}

Expand Down

0 comments on commit 1cfb14a

Please sign in to comment.