vim-patch:partial:9.0.1237: code is indented more than necessary (#21971)

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes vim/vim#11858)

6ec6666047

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2023-01-24 08:43:51 +08:00
committed by GitHub
parent dbb6c7f1b8
commit fa12b9ca2b
11 changed files with 559 additions and 491 deletions

View File

@@ -126,12 +126,14 @@ static char *provider_err = NULL;
void conceal_check_cursor_line(void)
{
bool should_conceal = conceal_cursor_line(curwin);
if (curwin->w_p_cole > 0 && (conceal_cursor_used != should_conceal)) {
if (curwin->w_p_cole <= 0 || conceal_cursor_used == should_conceal) {
return;
}
redrawWinline(curwin, curwin->w_cursor.lnum);
// Need to recompute cursor column, e.g., when starting Visual mode
// without concealing.
curs_columns(curwin, true);
}
}
/// Resize default_grid to Rows and Columns.
@@ -837,25 +839,29 @@ static bool vsep_connected(win_T *wp, WindowCorner corner)
/// Draw the vertical separator right of window "wp"
static void draw_vsep_win(win_T *wp)
{
if (wp->w_vsep_width) {
if (!wp->w_vsep_width) {
return;
}
// draw the vertical separator right of this window
int hl;
int c = fillchar_vsep(wp, &hl);
grid_fill(&default_grid, wp->w_winrow, W_ENDROW(wp),
W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl);
}
}
/// Draw the horizontal separator below window "wp"
static void draw_hsep_win(win_T *wp)
{
if (wp->w_hsep_height) {
if (!wp->w_hsep_height) {
return;
}
// draw the horizontal separator below this window
int hl;
int c = fillchar_hsep(wp, &hl);
grid_fill(&default_grid, W_ENDROW(wp), W_ENDROW(wp) + 1,
wp->w_wincol, W_ENDCOL(wp), c, c, hl);
}
}
/// Get the separator connector for specified window corner of window "wp"

View File

@@ -112,7 +112,10 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
frame_T *frc;
int count = 0;
if (fr->fr_layout != FR_LEAF) {
if (fr->fr_layout == FR_LEAF) {
return OK;
}
// Find first frame that's not skipped and then create a window for
// each following one (first frame is already there).
frc = ses_skipframe(fr->fr_child);
@@ -145,7 +148,7 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
return FAIL;
}
}
}
return OK;
}
@@ -906,12 +909,14 @@ static int makeopens(FILE *fd, char *dirnow)
void ex_loadview(exarg_T *eap)
{
char *fname = get_view_file(*eap->arg);
if (fname != NULL) {
if (fname == NULL) {
return;
}
if (do_source(fname, false, DOSO_NONE) == FAIL) {
semsg(_(e_notopen), fname);
}
xfree(fname);
}
}
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".

View File

@@ -142,16 +142,16 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr)
/// Also return its attribute in *attrp;
void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp)
{
size_t off;
grid_adjust(&grid, &row, &col);
// safety check
if (grid->chars != NULL && row < grid->rows && col < grid->cols) {
off = grid->line_offset[row] + (size_t)col;
if (grid->chars == NULL || row >= grid->rows || col >= grid->cols) {
return;
}
size_t off = grid->line_offset[row] + (size_t)col;
*attrp = grid->attrs[off];
schar_copy(bytes, grid->chars[off]);
}
}
/// put string '*text' on the window grid at position 'row' and 'col', with

View File

@@ -821,12 +821,14 @@ static void source_all_matches(char *pat)
int num_files;
char **files;
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) {
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) != OK) {
return;
}
for (int i = 0; i < num_files; i++) {
(void)do_source(files[i], false, DOSO_NONE);
}
FreeWild(num_files, files);
}
}
/// Add the package directory to 'runtimepath'

View File

@@ -295,7 +295,6 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
return false;
}
{
buf_T *old_curbuf = curbuf;
win_T *old_curwin = curwin;
char *s;
@@ -319,28 +318,31 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
buf[0] = NUL;
}
xfree(s);
}
return buf[0] != NUL;
}
/// Prepare for 'hlsearch' highlighting.
void start_search_hl(void)
{
if (p_hls && !no_hlsearch) {
if (!p_hls || no_hlsearch) {
return;
}
end_search_hl(); // just in case it wasn't called before
last_pat_prog(&screen_search_hl.rm);
// Set the time limit to 'redrawtime'.
screen_search_hl.tm = profile_setlimit(p_rdt);
}
}
/// Clean up for 'hlsearch' highlighting.
void end_search_hl(void)
{
if (screen_search_hl.rm.regprog != NULL) {
if (screen_search_hl.rm.regprog == NULL) {
return;
}
vim_regfree(screen_search_hl.rm.regprog);
screen_search_hl.rm.regprog = NULL;
}
}
/// Check if there should be a delay. Used before clearing or redrawing the
@@ -671,11 +673,13 @@ void clearmode(void)
static void recording_mode(int attr)
{
msg_puts_attr(_("recording"), attr);
if (!shortmess(SHM_RECORDING)) {
if (shortmess(SHM_RECORDING)) {
return;
}
char s[4];
snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording);
msg_puts_attr(s, attr);
}
}
void get_trans_bufname(buf_T *buf)

View File

@@ -206,7 +206,10 @@ char *get_search_pat(void)
void save_re_pat(int idx, char *pat, int magic)
{
if (spats[idx].pat != pat) {
if (spats[idx].pat == pat) {
return;
}
free_spat(&spats[idx]);
spats[idx].pat = xstrdup(pat);
spats[idx].magic = magic;
@@ -219,7 +222,6 @@ void save_re_pat(int idx, char *pat, int magic)
redraw_all_later(UPD_SOME_VALID);
}
set_no_hlsearch(false);
}
}
// Save the search patterns, so they can be restored later.
@@ -228,7 +230,10 @@ static int save_level = 0;
void save_search_patterns(void)
{
if (save_level++ == 0) {
if (save_level++ != 0) {
return;
}
saved_spats[0] = spats[0];
if (spats[0].pat != NULL) {
saved_spats[0].pat = xstrdup(spats[0].pat);
@@ -244,12 +249,14 @@ void save_search_patterns(void)
}
saved_spats_last_idx = last_idx;
saved_spats_no_hlsearch = no_hlsearch;
}
}
void restore_search_patterns(void)
{
if (--save_level == 0) {
if (--save_level != 0) {
return;
}
free_spat(&spats[0]);
spats[0] = saved_spats[0];
set_vv_searchforward();
@@ -259,7 +266,6 @@ void restore_search_patterns(void)
mr_pattern = saved_mr_pattern;
last_idx = saved_spats_last_idx;
set_no_hlsearch(saved_spats_no_hlsearch);
}
}
static inline void free_spat(struct spat *const spat)
@@ -2321,14 +2327,24 @@ void showmatch(int c)
if ((lpos = findmatch(NULL, NUL)) == NULL) { // no match, so beep
vim_beep(BO_MATCH);
} else if (lpos->lnum >= curwin->w_topline
&& lpos->lnum < curwin->w_botline) {
return;
}
if (lpos->lnum < curwin->w_topline || lpos->lnum >= curwin->w_botline) {
return;
}
if (!curwin->w_p_wrap) {
getvcol(curwin, lpos, NULL, &vcol, NULL);
}
if (curwin->w_p_wrap
bool col_visible = curwin->w_p_wrap
|| (vcol >= curwin->w_leftcol
&& vcol < curwin->w_leftcol + curwin->w_width_inner)) {
&& vcol < curwin->w_leftcol + curwin->w_width_inner);
if (!col_visible) {
return;
}
mpos = *lpos; // save the pos, update_screen() may change it
save_cursor = curwin->w_cursor;
save_so = *so;
@@ -2368,8 +2384,6 @@ void showmatch(int c)
*siso = save_siso;
State = save_state;
ui_cursor_shape(); // may show different cursor shape
}
}
}
/// Find next search match under cursor, cursor at end.
@@ -2588,7 +2602,10 @@ static void cmdline_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, bool sh
update_search_stat(dirc, pos, cursor_pos, &stat, recompute, maxcount,
timeout);
if (stat.cur > 0) {
if (stat.cur <= 0) {
return;
}
char t[SEARCH_STAT_BUF_LEN];
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') {
@@ -2637,7 +2654,6 @@ static void cmdline_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, bool sh
msg_ext_set_kind("search_count");
give_warning(msgbuf, false);
msg_hist_off = false;
}
}
// Add the search count information to "stat".

View File

@@ -122,18 +122,18 @@ static signgroup_T *sign_group_ref(const char *groupname)
/// removed, then remove the group.
static void sign_group_unref(char *groupname)
{
signgroup_T *group;
hashitem_T *hi = hash_find(&sg_table, groupname);
if (!HASHITEM_EMPTY(hi)) {
group = HI2SG(hi);
if (HASHITEM_EMPTY(hi)) {
return;
}
signgroup_T *group = HI2SG(hi);
group->sg_refcount--;
if (group->sg_refcount == 0) {
// All the signs in this group are removed
hash_remove(&sg_table, hi);
xfree(group);
}
}
}
/// @return true if 'sign' is in 'group'.

View File

@@ -1488,7 +1488,10 @@ void spell_cat_line(char *buf, char *line, int maxlen)
p = (char_u *)skipwhite((char *)p + 1);
}
if (*p != NUL) {
if (*p == NUL) {
return;
}
// Only worth concatenating if there is something else than spaces to
// concatenate.
int n = (int)(p - (char_u *)line) + 1;
@@ -1496,7 +1499,6 @@ void spell_cat_line(char *buf, char *line, int maxlen)
memset(buf, ' ', (size_t)n);
xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n));
}
}
}
// Load word list(s) for "lang" from Vim spell file(s).
@@ -1702,7 +1704,10 @@ static void spell_load_cb(char *fname, void *cookie)
{
spelload_T *slp = (spelload_T *)cookie;
slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false);
if (slang != NULL) {
if (slang == NULL) {
return;
}
// When a previously loaded file has NOBREAK also use it for the
// ".add" files.
if (slp->sl_nobreak && slang->sl_add) {
@@ -1712,7 +1717,6 @@ static void spell_load_cb(char *fname, void *cookie)
}
slp->sl_slang = slang;
}
}
/// Add a word to the hashtable of common words.
@@ -2258,13 +2262,15 @@ int captype(char *word, const char *end)
// Delete the internal wordlist and its .spl file.
void spell_delete_wordlist(void)
{
if (int_wordlist != NULL) {
if (int_wordlist == NULL) {
return;
}
char fname[MAXPATHL] = { 0 };
os_remove(int_wordlist);
int_wordlist_spl(fname);
os_remove(fname);
XFREE_CLEAR(int_wordlist);
}
}
// Free all languages.
@@ -2332,10 +2338,12 @@ buf_T *open_spellbuf(void)
// Close the buffer used for spell info.
void close_spellbuf(buf_T *buf)
{
if (buf != NULL) {
if (buf == NULL) {
return;
}
ml_close(buf, true);
xfree(buf);
}
}
// Init the chartab used for spelling for ASCII.
@@ -3624,15 +3632,16 @@ char *did_set_spell_option(bool is_spellfile)
}
}
if (errmsg == NULL) {
if (errmsg != NULL) {
return errmsg;
}
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_buffer == curbuf && wp->w_p_spell) {
errmsg = did_set_spelllang(wp);
break;
}
}
}
return errmsg;
}

View File

@@ -1695,7 +1695,10 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs
// Invalid length, multiply with sizeof(int) would overflow.
return SP_FORMERROR;
}
if (len > 0) {
if (len <= 0) {
return 0;
}
// Allocate the byte array.
bp = xmalloc((size_t)len);
*bytsp = bp;
@@ -1712,7 +1715,6 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs
if (idx < 0) {
return idx;
}
}
return 0;
}
@@ -2003,14 +2005,15 @@ static void spell_print_node(wordnode_T *node, int depth)
static void spell_print_tree(wordnode_T *root)
{
if (root != NULL) {
// Clear the "wn_u1.index" fields, used to remember what has been
// done.
if (root == NULL) {
return;
}
// Clear the "wn_u1.index" fields, used to remember what has been done.
spell_clear_flags(root);
// Recursively print the tree.
spell_print_node(root, 0);
}
}
#endif // SPELL_PRINTTREE
@@ -4197,7 +4200,10 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n
// Skip the root itself, it's not actually used. The first sibling is the
// start of the tree.
if (root->wn_sibling != NULL) {
if (root->wn_sibling == NULL) {
return;
}
hash_init(&ht);
const long n = node_compress(spin, root->wn_sibling, &ht, &tot);
@@ -4221,7 +4227,6 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n
spell_print_tree(root->wn_sibling);
#endif
hash_clear(&ht);
}
}
/// Compress a node, its siblings and its children, depth first.
@@ -4887,10 +4892,12 @@ void ex_mkspell(exarg_T *eap)
}
// Expand all the remaining arguments (e.g., $VIMRUNTIME).
if (get_arglist_exp(arg, &fcount, &fnames, false) == OK) {
if (get_arglist_exp(arg, &fcount, &fnames, false) != OK) {
return;
}
mkspell(fcount, fnames, ascii, eap->forceit, false);
FreeWild(fcount, fnames);
}
}
// Create the .sug file.
@@ -5681,7 +5688,10 @@ static void init_spellfile(void)
bool aspath = false;
char *lstart = curbuf->b_s.b_p_spl;
if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) {
if (*curwin->w_s->b_p_spl == NUL || GA_EMPTY(&curwin->w_s->b_langp)) {
return;
}
buf = xmalloc(MAXPATHL);
// Find the end of the language name. Exclude the region. If there
@@ -5738,7 +5748,6 @@ static void init_spellfile(void)
}
xfree(buf);
}
}
/// Set the spell character tables from strings in the .spl file.

View File

@@ -276,7 +276,10 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl
int newscore;
hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word);
if (!HASHITEM_EMPTY(hi)) {
if (HASHITEM_EMPTY(hi)) {
return score;
}
wc = HI2WC(hi);
if (wc->wc_count < SCORE_THRES2) {
bonus = SCORE_COMMON1;
@@ -294,8 +297,6 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl
return 0;
}
return newscore;
}
return score;
}
/// Like captype() but for a KEEPCAP word add ONECAP if the word starts with a
@@ -310,7 +311,10 @@ static int badword_captype(char_u *word, char_u *end)
bool first;
char_u *p;
if (flags & WF_KEEPCAP) {
if (!(flags & WF_KEEPCAP)) {
return flags;
}
// Count the number of UPPER and lower case letters.
l = u = 0;
first = false;
@@ -339,7 +343,7 @@ static int badword_captype(char_u *word, char_u *end)
if (u >= 2 && l >= 2) { // maCARONI maCAroni
flags |= WF_MIXCAP;
}
}
return flags;
}
@@ -3247,10 +3251,11 @@ static void add_banned(suginfo_T *su, char *word)
hash = hash_hash(word);
const size_t word_len = strlen(word);
hi = hash_lookup(&su->su_banned, word, word_len, hash);
if (HASHITEM_EMPTY(hi)) {
if (!HASHITEM_EMPTY(hi)) { // already present
return;
}
s = xmemdupz(word, word_len);
hash_add_item(&su->su_banned, hi, (char *)s, hash);
}
}
/// Recompute the score for all suggestions if sound-folding is possible. This
@@ -3317,7 +3322,10 @@ static int sug_compare(const void *s1, const void *s2)
static int cleanup_suggestions(garray_T *gap, int maxscore, int keep)
FUNC_ATTR_NONNULL_ALL
{
if (gap->ga_len > 0) {
if (gap->ga_len <= 0) {
return maxscore;
}
// Sort the list.
qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
@@ -3333,7 +3341,6 @@ static int cleanup_suggestions(garray_T *gap, int maxscore, int keep)
return stp[keep - 1].st_score;
}
}
}
return maxscore;
}

View File

@@ -721,10 +721,12 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
static void save_chartab(char *chartab)
{
if (syn_block->b_syn_isk != empty_option) {
if (syn_block->b_syn_isk == empty_option) {
return;
}
memmove(chartab, syn_buf->b_chartab, (size_t)32);
memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32);
}
}
static void restore_chartab(char *chartab)
@@ -737,7 +739,10 @@ static void restore_chartab(char *chartab)
/// Return true if the line-continuation pattern matches in line "lnum".
static int syn_match_linecont(linenr_T lnum)
{
if (syn_block->b_syn_linecont_prog != NULL) {
if (syn_block->b_syn_linecont_prog == NULL) {
return false;
}
regmmatch_T regmatch;
// chartab array for syn iskeyword
char buf_chartab[32];
@@ -751,8 +756,6 @@ static int syn_match_linecont(linenr_T lnum)
restore_chartab(buf_chartab);
return r;
}
return false;
}
// Prepare the current state for the start of a line.
@@ -873,14 +876,16 @@ static void syn_stack_free_block(synblock_T *block)
{
synstate_T *p;
if (block->b_sst_array != NULL) {
if (block->b_sst_array == NULL) {
return;
}
for (p = block->b_sst_first; p != NULL; p = p->sst_next) {
clear_syn_state(p);
}
XFREE_CLEAR(block->b_sst_array);
block->b_sst_first = NULL;
block->b_sst_len = 0;
}
}
// Free b_sst_array[] for buffer "buf".
// Used when syntax items changed to force resyncing everywhere.
@@ -5369,10 +5374,17 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
include_link = 0;
include_default = 0;
if (*arg == NUL) {
return;
}
// (part of) subcommand already typed
if (*arg != NUL) {
const char *p = (const char *)skiptowhite(arg);
if (*p != NUL) { // Past first word.
if (*p == NUL) {
return;
}
// past first world
xp->xp_pattern = skipwhite(p);
if (*skiptowhite(xp->xp_pattern) != NUL) {
xp->xp_context = EXPAND_NOTHING;
@@ -5396,8 +5408,6 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
} else {
xp->xp_context = EXPAND_NOTHING;
}
}
}
}
// Function given to ExpandGeneric() to obtain the list syntax names for