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 vim/vim#8061)
440cf096fa
This commit is contained in:
Shougo Matsushita
2021-04-05 09:10:43 +09:00
parent 9b2d4ff625
commit 356a35a848
3 changed files with 11 additions and 8 deletions

View File

@@ -2523,7 +2523,8 @@ static void ins_compl_add_matches(int num_matches, char_u **matches, int icase)
for (int i = 0; i < num_matches && add_r != FAIL; i++) { for (int i = 0; i < num_matches && add_r != FAIL; i++) {
if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, NULL, dir, if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, 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;
} }
@@ -2598,7 +2599,7 @@ void set_completion(colnr_T startcol, list_T *list)
flags |= CP_ICASE; flags |= CP_ICASE;
} }
if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, NULL, 0, if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, NULL, 0,
flags, false) != OK) { flags | CP_FAST, false) != OK) {
return; return;
} }
@@ -3318,8 +3319,8 @@ static int ins_compl_bs(void)
// allow the word to be deleted, we won't match everything. // allow the word to be deleted, we won't match everything.
// 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_OMNI) || ctrl_x_mode == CTRL_X_EVAL || 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;
@@ -3934,7 +3935,7 @@ static void ins_compl_add_list(list_T *const list)
// Go through the List with matches and add each of them. // Go through the List with matches and add each of them.
TV_LIST_ITER(list, li, { TV_LIST_ITER(list, li, {
if (ins_compl_add_tv(TV_LIST_ITEM_TV(li), dir) == OK) { if (ins_compl_add_tv(TV_LIST_ITEM_TV(li), 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) {
@@ -3973,17 +3974,18 @@ static void ins_compl_add_dict(dict_T *dict)
/// ///
/// @param[in] tv Object to get matches from. /// @param[in] tv Object to get matches from.
/// @param[in] dir Completion direction. /// @param[in] dir Completion direction.
/// @param[in] fast use fast_breakcheck() instead of ui_breakcheck().
/// ///
/// @return NOTDONE if the given string is already in the list of completions, /// @return NOTDONE if the given string is already in the list of completions,
/// otherwise it is added to the list and OK is returned. FAIL will be /// otherwise it is added to the list and OK is returned. FAIL will be
/// returned in case of error. /// returned in case of error.
int ins_compl_add_tv(typval_T *const tv, const Direction dir) int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
const char *word; const char *word;
bool dup = false; bool dup = false;
bool empty = false; bool empty = false;
int flags = 0; int flags = fast ? CP_FAST : 0;
char *(cptext[CPT_COUNT]); char *(cptext[CPT_COUNT]);
typval_T user_data; typval_T user_data;

View File

@@ -19,6 +19,7 @@ typedef enum {
CP_CONT_S_IPOS = 4, // use CONT_S_IPOS for compl_cont_status CP_CONT_S_IPOS = 4, // use CONT_S_IPOS for compl_cont_status
CP_EQUAL = 8, // ins_compl_equal() always returns true CP_EQUAL = 8, // ins_compl_equal() always returns true
CP_ICASE = 16, // ins_compl_equal ignores case CP_ICASE = 16, // ins_compl_equal ignores case
CP_FAST = 32, // use fast_breakcheck instead of ui_breakcheck
} cp_flags_T; } cp_flags_T;
typedef int (*IndentGetter)(void); typedef int (*IndentGetter)(void);

View File

@@ -1098,7 +1098,7 @@ static void f_complete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/ */
static void f_complete_add(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_complete_add(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {
rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0); rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0, false);
} }
/* /*