diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-24 08:43:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-24 08:43:51 +0800 |
commit | fa12b9ca2b1dd5515910875e04fe36564fbaadcc (patch) | |
tree | a9db5e808937b47883a341eabda44af00e0df878 /src/nvim/spell.c | |
parent | dbb6c7f1b8bed789f5bebb73be332c063fc6a604 (diff) | |
download | rneovim-fa12b9ca2b1dd5515910875e04fe36564fbaadcc.tar.gz rneovim-fa12b9ca2b1dd5515910875e04fe36564fbaadcc.tar.bz2 rneovim-fa12b9ca2b1dd5515910875e04fe36564fbaadcc.zip |
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)
https://github.com/vim/vim/commit/6ec66660476562e643deceb7c325cd0e8c903663
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/spell.c')
-rw-r--r-- | src/nvim/spell.c | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 215c546f83..8e18be5bd1 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1488,14 +1488,16 @@ void spell_cat_line(char *buf, char *line, int maxlen) p = (char_u *)skipwhite((char *)p + 1); } - if (*p != NUL) { - // Only worth concatenating if there is something else than spaces to - // concatenate. - int n = (int)(p - (char_u *)line) + 1; - if (n < maxlen - 1) { - memset(buf, ' ', (size_t)n); - xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n)); - } + if (*p == NUL) { + return; + } + + // Only worth concatenating if there is something else than spaces to + // concatenate. + int n = (int)(p - (char_u *)line) + 1; + if (n < maxlen - 1) { + memset(buf, ' ', (size_t)n); + xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n)); } } @@ -1702,17 +1704,19 @@ 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) { - // When a previously loaded file has NOBREAK also use it for the - // ".add" files. - if (slp->sl_nobreak && slang->sl_add) { - slang->sl_nobreak = true; - } else if (slang->sl_nobreak) { - slp->sl_nobreak = true; - } + if (slang == NULL) { + return; + } - slp->sl_slang = slang; + // When a previously loaded file has NOBREAK also use it for the + // ".add" files. + if (slp->sl_nobreak && slang->sl_add) { + slang->sl_nobreak = true; + } else if (slang->sl_nobreak) { + slp->sl_nobreak = true; } + + 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) { - char fname[MAXPATHL] = { 0 }; - os_remove(int_wordlist); - int_wordlist_spl(fname); - os_remove(fname); - XFREE_CLEAR(int_wordlist); + 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) { - ml_close(buf, true); - xfree(buf); + 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) { - FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (wp->w_buffer == curbuf && wp->w_p_spell) { - errmsg = did_set_spelllang(wp); - break; - } - } + 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; } |