1
0
forked from aniani/vim

patch 8.2.2704: adding a lot of completions can be a bit slow

Problem:    Adding a lot of completions can be a bit slow.
Solution:   Use fast_breakcheck() instead of ui_breakcheck() when adding a
            list of completions. (Ben Jackson, closes #8061)
This commit is contained in:
Bram Moolenaar
2021-04-03 20:13:30 +02:00
parent 6e50ec2f0a
commit 440cf096fa
2 changed files with 13 additions and 7 deletions

View File

@@ -118,6 +118,7 @@ struct compl_S
# define CP_CONT_S_IPOS 4 // use CONT_S_IPOS for compl_cont_status # define CP_CONT_S_IPOS 4 // use CONT_S_IPOS for compl_cont_status
# define CP_EQUAL 8 // ins_compl_equal() always returns TRUE # define CP_EQUAL 8 // ins_compl_equal() always returns TRUE
# define CP_ICASE 16 // ins_compl_equal() ignores case # define CP_ICASE 16 // ins_compl_equal() ignores case
# define CP_FAST 32 // use fast_breakcheck instead of ui_breakcheck
static char e_hitend[] = N_("Hit end of paragraph"); static char e_hitend[] = N_("Hit end of paragraph");
# ifdef FEAT_COMPL_FUNC # ifdef FEAT_COMPL_FUNC
@@ -790,7 +791,7 @@ ins_compl_add_matches(
for (i = 0; i < num_matches && add_r != FAIL; i++) for (i = 0; i < num_matches && add_r != FAIL; i++)
if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, NULL, dir, if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, NULL, dir,
icase ? CP_ICASE : 0, FALSE)) == OK) CP_FAST | (icase ? CP_ICASE : 0), FALSE)) == OK)
// if dir was BACKWARD then honor it just once // if dir was BACKWARD then honor it just once
dir = FORWARD; dir = FORWARD;
FreeWild(num_matches, matches); FreeWild(num_matches, matches);
@@ -1567,7 +1568,8 @@ ins_compl_bs(void)
// Respect the 'backspace' option. // Respect the 'backspace' option.
if ((int)(p - line) - (int)compl_col < 0 if ((int)(p - line) - (int)compl_col < 0
|| ((int)(p - line) - (int)compl_col == 0 || ((int)(p - line) - (int)compl_col == 0
&& ctrl_x_mode != CTRL_X_OMNI) || ctrl_x_mode == CTRL_X_EVAL && ctrl_x_mode != CTRL_X_OMNI)
|| ctrl_x_mode == CTRL_X_EVAL
|| (!can_bs(BS_START) && (int)(p - line) - (int)compl_col || (!can_bs(BS_START) && (int)(p - line) - (int)compl_col
- compl_length < 0)) - compl_length < 0))
return K_BS; return K_BS;
@@ -2271,14 +2273,15 @@ theend:
* If the given string is already in the list of completions, then return * If the given string is already in the list of completions, then return
* NOTDONE, otherwise add it to the list and return OK. If there is an error, * NOTDONE, otherwise add it to the list and return OK. If there is an error,
* maybe because alloc() returns NULL, then FAIL is returned. * maybe because alloc() returns NULL, then FAIL is returned.
* When "fast" is TRUE use fast_breakcheck() instead of ui_breakcheck().
*/ */
static int static int
ins_compl_add_tv(typval_T *tv, int dir) ins_compl_add_tv(typval_T *tv, int dir, int fast)
{ {
char_u *word; char_u *word;
int dup = FALSE; int dup = FALSE;
int empty = FALSE; int empty = FALSE;
int flags = 0; int flags = fast ? CP_FAST : 0;
char_u *(cptext[CPT_COUNT]); char_u *(cptext[CPT_COUNT]);
typval_T user_data; typval_T user_data;
@@ -2329,7 +2332,7 @@ ins_compl_add_list(list_T *list)
CHECK_LIST_MATERIALIZE(list); CHECK_LIST_MATERIALIZE(list);
FOR_ALL_LIST_ITEMS(list, li) FOR_ALL_LIST_ITEMS(list, li)
{ {
if (ins_compl_add_tv(&li->li_tv, dir) == OK) if (ins_compl_add_tv(&li->li_tv, dir, TRUE) == OK)
// if dir was BACKWARD then honor it just once // if dir was BACKWARD then honor it just once
dir = FORWARD; dir = FORWARD;
else if (did_emsg) else if (did_emsg)
@@ -2391,7 +2394,8 @@ set_completion(colnr_T startcol, list_T *list)
if (p_ic) if (p_ic)
flags |= CP_ICASE; flags |= CP_ICASE;
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
-1, NULL, NULL, NULL, 0, flags, FALSE) != OK) -1, NULL, NULL, NULL, 0,
flags | CP_FAST, FALSE) != OK)
return; return;
ctrl_x_mode = CTRL_X_EVAL; ctrl_x_mode = CTRL_X_EVAL;
@@ -2461,7 +2465,7 @@ f_complete(typval_T *argvars, typval_T *rettv UNUSED)
void void
f_complete_add(typval_T *argvars, typval_T *rettv) f_complete_add(typval_T *argvars, typval_T *rettv)
{ {
rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0); rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0, FALSE);
} }
/* /*

View File

@@ -750,6 +750,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 */
/**/
2704,
/**/ /**/
2703, 2703,
/**/ /**/