diff src/syntax.c @ 31809:543153d582d5 v9.0.1237

patch 9.0.1237: code is indented more than necessary Commit: https://github.com/vim/vim/commit/6ec66660476562e643deceb7c325cd0e8c903663 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Jan 23 20:46:21 2023 +0000 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)
author Bram Moolenaar <Bram@vim.org>
date Mon, 23 Jan 2023 22:00:04 +0100
parents 53c3df37a2b0
children e16361210675
line wrap: on
line diff
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -855,12 +855,11 @@ syn_sync(
     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 @@ syn_match_linecont(linenr_T lnum)
     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(&regmatch, 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(&regmatch, 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 @@ syn_stack_free_block(synblock_T *block)
 {
     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 @@ syn_scl_namen2id(char_u *linep, int len)
     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 @@ ex_syntax(exarg_T *eap)
     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 @@ set_context_in_syntax_cmd(expand_T *xp, 
     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;
 }
 
 /*