summaryrefslogtreecommitdiffstats
path: root/src/cindent.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-01-09 19:04:23 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-09 19:04:23 +0000
commit1cfb14aa972ccf3235ac67f07b7db1175b7c5384 (patch)
treeb746eda548993b9e0987d7c9c0c543ddddc5758f /src/cindent.c
parent765d82a657c5e42d5d7c88ae410e53f398c34c43 (diff)
patch 9.0.1166: code is indented more than necessaryv9.0.1166
Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11792)
Diffstat (limited to 'src/cindent.c')
-rw-r--r--src/cindent.c107
1 files changed, 53 insertions, 54 deletions
diff --git a/src/cindent.c b/src/cindent.c
index 105e08cc8c..bc71cc092f 100644
--- a/src/cindent.c
+++ b/src/cindent.c
@@ -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;
}
@@ -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???
}
/*
@@ -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;
}