Mercurial > vim
diff src/spellsuggest.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 | c7983f593fa7 |
children | 9f28cca2410a |
line wrap: on
line diff
--- a/src/spellsuggest.c +++ b/src/spellsuggest.c @@ -282,24 +282,23 @@ score_wordcount_adj( int newscore; hi = hash_find(&slang->sl_wordcount, word); - if (!HASHITEM_EMPTY(hi)) - { - wc = HI2WC(hi); - if (wc->wc_count < SCORE_THRES2) - bonus = SCORE_COMMON1; - else if (wc->wc_count < SCORE_THRES3) - bonus = SCORE_COMMON2; - else - bonus = SCORE_COMMON3; - if (split) - newscore = score - bonus / 2; - else - newscore = score - bonus; - if (newscore < 0) - return 0; - return newscore; - } - return score; + if (HASHITEM_EMPTY(hi)) + return score; + + wc = HI2WC(hi); + if (wc->wc_count < SCORE_THRES2) + bonus = SCORE_COMMON1; + else if (wc->wc_count < SCORE_THRES3) + bonus = SCORE_COMMON2; + else + bonus = SCORE_COMMON3; + if (split) + newscore = score - bonus / 2; + else + newscore = score - bonus; + if (newscore < 0) + return 0; + return newscore; } /* @@ -316,36 +315,37 @@ badword_captype(char_u *word, char_u *en int 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; + for (p = word; p < end; MB_PTR_ADV(p)) { - // Count the number of UPPER and lower case letters. - l = u = 0; - first = FALSE; - for (p = word; p < end; MB_PTR_ADV(p)) + c = PTR2CHAR(p); + if (SPELL_ISUPPER(c)) { - c = PTR2CHAR(p); - if (SPELL_ISUPPER(c)) - { - ++u; - if (p == word) - first = TRUE; - } - else - ++l; + ++u; + if (p == word) + first = TRUE; } - - // If there are more UPPER than lower case letters suggest an - // ALLCAP word. Otherwise, if the first letter is UPPER then - // suggest ONECAP. Exception: "ALl" most likely should be "All", - // require three upper case letters. - if (u > l && u > 2) - flags |= WF_ALLCAP; - else if (first) - flags |= WF_ONECAP; - - if (u >= 2 && l >= 2) // maCARONI maCAroni - flags |= WF_MIXCAP; + else + ++l; } + + // If there are more UPPER than lower case letters suggest an + // ALLCAP word. Otherwise, if the first letter is UPPER then + // suggest ONECAP. Exception: "ALl" most likely should be "All", + // require three upper case letters. + if (u > l && u > 2) + flags |= WF_ALLCAP; + else if (first) + flags |= WF_ONECAP; + + if (u >= 2 && l >= 2) // maCARONI maCAroni + flags |= WF_MIXCAP; + return flags; } @@ -3692,12 +3692,11 @@ add_banned( hash = hash_hash(word); hi = hash_lookup(&su->su_banned, word, hash); - if (HASHITEM_EMPTY(hi)) - { - s = vim_strsave(word); - if (s != NULL) - hash_add_item(&su->su_banned, hi, s, hash); - } + if (!HASHITEM_EMPTY(hi)) // already present + return; + s = vim_strsave(word); + if (s != NULL) + hash_add_item(&su->su_banned, hi, s, hash); } /* @@ -3778,25 +3777,25 @@ cleanup_suggestions( int maxscore, int keep) // nr of suggestions to keep { - 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); + + // Truncate the list to the number of suggestions that will be + // displayed. + if (gap->ga_len > keep) { - // Sort the list. - qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), - sug_compare); - - // Truncate the list to the number of suggestions that will be - // displayed. - if (gap->ga_len > keep) - { - int i; - suggest_T *stp = &SUG(*gap, 0); - - for (i = keep; i < gap->ga_len; ++i) - vim_free(stp[i].st_word); - gap->ga_len = keep; - if (keep >= 1) - return stp[keep - 1].st_score; - } + int i; + suggest_T *stp = &SUG(*gap, 0); + + for (i = keep; i < gap->ga_len; ++i) + vim_free(stp[i].st_word); + gap->ga_len = keep; + if (keep >= 1) + return stp[keep - 1].st_score; } return maxscore; }