patch 9.0.1237: 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 #11858)
diff --git a/src/syntax.c b/src/syntax.c
index 7211da3..614f52e 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -855,12 +855,11 @@
static void
save_chartab(char_u *chartab)
{
- if (syn_block->b_syn_isk != empty_option)
- {
- mch_memmove(chartab, syn_buf->b_chartab, (size_t)32);
- mch_memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab,
- (size_t)32);
- }
+ if (syn_block->b_syn_isk == empty_option)
+ return;
+
+ mch_memmove(chartab, syn_buf->b_chartab, (size_t)32);
+ mch_memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32);
}
static void
@@ -880,19 +879,18 @@
int r;
char_u buf_chartab[32]; // chartab array for syn iskyeyword
- if (syn_block->b_syn_linecont_prog != NULL)
- {
- // use syntax iskeyword option
- save_chartab(buf_chartab);
- regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
- regmatch.regprog = syn_block->b_syn_linecont_prog;
- r = syn_regexec(®match, lnum, (colnr_T)0,
- IF_SYN_TIME(&syn_block->b_syn_linecont_time));
- syn_block->b_syn_linecont_prog = regmatch.regprog;
- restore_chartab(buf_chartab);
- return r;
- }
- return FALSE;
+ if (syn_block->b_syn_linecont_prog == NULL)
+ return FALSE;
+
+ // use syntax iskeyword option
+ save_chartab(buf_chartab);
+ regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
+ regmatch.regprog = syn_block->b_syn_linecont_prog;
+ r = syn_regexec(®match, lnum, (colnr_T)0,
+ IF_SYN_TIME(&syn_block->b_syn_linecont_time));
+ syn_block->b_syn_linecont_prog = regmatch.regprog;
+ restore_chartab(buf_chartab);
+ return r;
}
/*
@@ -1030,14 +1028,14 @@
{
synstate_T *p;
- if (block->b_sst_array != NULL)
- {
- FOR_ALL_SYNSTATES(block, p)
- clear_syn_state(p);
- VIM_CLEAR(block->b_sst_array);
- block->b_sst_first = NULL;
- block->b_sst_len = 0;
- }
+ if (block->b_sst_array == NULL)
+ return;
+
+ FOR_ALL_SYNSTATES(block, p)
+ clear_syn_state(p);
+ VIM_CLEAR(block->b_sst_array);
+ block->b_sst_first = NULL;
+ block->b_sst_len = 0;
}
/*
* Free b_sst_array[] for buffer "buf".
@@ -5437,11 +5435,11 @@
int id = 0;
name = vim_strnsave(linep, len);
- if (name != NULL)
- {
- id = syn_scl_name2id(name);
- vim_free(name);
- }
+ if (name == NULL)
+ return 0;
+
+ id = syn_scl_name2id(name);
+ vim_free(name);
return id;
}
@@ -6256,28 +6254,28 @@
for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end)
;
subcmd_name = vim_strnsave(arg, subcmd_end - arg);
- if (subcmd_name != NULL)
+ if (subcmd_name == NULL)
+ return;
+
+ if (eap->skip) // skip error messages for all subcommands
+ ++emsg_skip;
+ for (i = 0; ; ++i)
{
- if (eap->skip) // skip error messages for all subcommands
- ++emsg_skip;
- for (i = 0; ; ++i)
+ if (subcommands[i].name == NULL)
{
- if (subcommands[i].name == NULL)
- {
- semsg(_(e_invalid_syntax_subcommand_str), subcmd_name);
- break;
- }
- if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0)
- {
- eap->arg = skipwhite(subcmd_end);
- (subcommands[i].func)(eap, FALSE);
- break;
- }
+ semsg(_(e_invalid_syntax_subcommand_str), subcmd_name);
+ break;
}
- vim_free(subcmd_name);
- if (eap->skip)
- --emsg_skip;
+ if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0)
+ {
+ eap->arg = skipwhite(subcmd_end);
+ (subcommands[i].func)(eap, FALSE);
+ break;
+ }
}
+ vim_free(subcmd_name);
+ if (eap->skip)
+ --emsg_skip;
}
void
@@ -6384,37 +6382,38 @@
include_link = 0;
include_default = 0;
+ if (*arg == NUL)
+ return;
+
// (part of) subcommand already typed
- if (*arg != NUL)
+ p = skiptowhite(arg);
+ if (*p == NUL)
+ return;
+
+ // past first word
+ xp->xp_pattern = skipwhite(p);
+ if (*skiptowhite(xp->xp_pattern) != NUL)
+ xp->xp_context = EXPAND_NOTHING;
+ else if (STRNICMP(arg, "case", p - arg) == 0)
+ expand_what = EXP_CASE;
+ else if (STRNICMP(arg, "spell", p - arg) == 0)
+ expand_what = EXP_SPELL;
+ else if (STRNICMP(arg, "sync", p - arg) == 0)
+ expand_what = EXP_SYNC;
+ else if (STRNICMP(arg, "list", p - arg) == 0)
{
- p = skiptowhite(arg);
- if (*p != NUL) // past first word
- {
- xp->xp_pattern = skipwhite(p);
- if (*skiptowhite(xp->xp_pattern) != NUL)
- xp->xp_context = EXPAND_NOTHING;
- else if (STRNICMP(arg, "case", p - arg) == 0)
- expand_what = EXP_CASE;
- else if (STRNICMP(arg, "spell", p - arg) == 0)
- expand_what = EXP_SPELL;
- else if (STRNICMP(arg, "sync", p - arg) == 0)
- expand_what = EXP_SYNC;
- else if (STRNICMP(arg, "list", p - arg) == 0)
- {
- p = skipwhite(p);
- if (*p == '@')
- expand_what = EXP_CLUSTER;
- else
- xp->xp_context = EXPAND_HIGHLIGHT;
- }
- else if (STRNICMP(arg, "keyword", p - arg) == 0
- || STRNICMP(arg, "region", p - arg) == 0
- || STRNICMP(arg, "match", p - arg) == 0)
- xp->xp_context = EXPAND_HIGHLIGHT;
- else
- xp->xp_context = EXPAND_NOTHING;
- }
+ p = skipwhite(p);
+ if (*p == '@')
+ expand_what = EXP_CLUSTER;
+ else
+ xp->xp_context = EXPAND_HIGHLIGHT;
}
+ else if (STRNICMP(arg, "keyword", p - arg) == 0
+ || STRNICMP(arg, "region", p - arg) == 0
+ || STRNICMP(arg, "match", p - arg) == 0)
+ xp->xp_context = EXPAND_HIGHLIGHT;
+ else
+ xp->xp_context = EXPAND_NOTHING;
}
/*