0
0
mirror of https://github.com/vim/vim.git synced 2025-10-30 09:47:20 -04:00

patch 9.1.1452: completion: redundant check for completion flags

Problem:  completion: redundant check for completion flags
Solution: refactor code slightly (glepnir)

refactor: nest fuzzy completion logic to avoid duplicate flag checks

- Combine COT_FUZZY checks into single nested condition
- Reduce redundant bitwise operations in ins_compl_new_leader()

closes: #17494

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
glepnir
2025-06-10 20:52:41 +02:00
committed by Christian Brabandt
parent 30b4ddf925
commit ecf8f15884
2 changed files with 16 additions and 12 deletions

View File

@@ -2316,6 +2316,7 @@ ins_compl_need_restart(void)
static void static void
ins_compl_new_leader(void) ins_compl_new_leader(void)
{ {
int cur_cot_flags = get_cot_flags();
ins_compl_del_pum(); ins_compl_del_pum();
ins_compl_delete(); ins_compl_delete();
ins_compl_insert_bytes(compl_leader.string + get_compl_len(), -1); ins_compl_insert_bytes(compl_leader.string + get_compl_len(), -1);
@@ -2350,15 +2351,15 @@ ins_compl_new_leader(void)
compl_restarting = FALSE; compl_restarting = FALSE;
} }
// When 'cot' contains "fuzzy" set the cp_score // When 'cot' contains "fuzzy" set the cp_score and maybe sort
if (get_cot_flags() & COT_FUZZY) if (cur_cot_flags & COT_FUZZY)
{
set_fuzzy_score(); set_fuzzy_score();
// Sort the matches linked list based on fuzzy score // Sort the matches linked list based on fuzzy score
int cur_cot_flags = get_cot_flags(); if (!(cur_cot_flags & COT_NOSORT))
if ((cur_cot_flags & COT_FUZZY) && !(cur_cot_flags & COT_NOSORT))
{ {
sort_compl_match_list(cp_compare_fuzzy); sort_compl_match_list(cp_compare_fuzzy);
if ((cur_cot_flags & COT_NOINSERT) && !(cur_cot_flags & COT_NOSELECT) if ((cur_cot_flags & (COT_NOINSERT | COT_NOSELECT)) == COT_NOINSERT
&& compl_first_match) && compl_first_match)
{ {
compl_shown_match = compl_first_match; compl_shown_match = compl_first_match;
@@ -2366,6 +2367,7 @@ ins_compl_new_leader(void)
compl_shown_match = compl_first_match->cp_next; compl_shown_match = compl_first_match->cp_next;
} }
} }
}
compl_enter_selects = !compl_used_match && compl_selected_item != -1; compl_enter_selects = !compl_used_match && compl_selected_item != -1;

View File

@@ -709,6 +709,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1452,
/**/ /**/
1451, 1451,
/**/ /**/