mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.1.0479: fuzzy_match_str_with_pos() does unnecessary list operations
Problem: fuzzy_match_str_with_pos() does unnecessary list operations. Solution: Use fuzzy_match() directly (zeertzjq). closes: #14987 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
d353d27820
commit
2f95ca9fce
@ -1,4 +1,4 @@
|
|||||||
*syntax.txt* For Vim version 9.1. Last change: 2024 Jun 11
|
*syntax.txt* For Vim version 9.1. Last change: 2024 Jun 13
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -5688,7 +5688,6 @@ PmenuThumb Popup menu: Thumb of the scrollbar.
|
|||||||
PmenuMatch Popup menu: Matched text in normal item
|
PmenuMatch Popup menu: Matched text in normal item
|
||||||
*hl-PmenuMatchSel*
|
*hl-PmenuMatchSel*
|
||||||
PmenuMatchSel Popup menu: Matched text in selected item
|
PmenuMatchSel Popup menu: Matched text in selected item
|
||||||
|
|
||||||
*hl-PopupNotification*
|
*hl-PopupNotification*
|
||||||
PopupNotification
|
PopupNotification
|
||||||
Popup window created with |popup_notification()|. If not
|
Popup window created with |popup_notification()|. If not
|
||||||
|
@ -463,8 +463,8 @@ pum_screen_put_with_attr(int row, int col, char_u *text, int textlen, int attr)
|
|||||||
// Handle fuzzy matching
|
// Handle fuzzy matching
|
||||||
for (i = 0; i < ga->ga_len; i++)
|
for (i = 0; i < ga->ga_len; i++)
|
||||||
{
|
{
|
||||||
int *match_pos = ((int *)ga->ga_data) + i;
|
int_u *match_pos = ((int_u *)ga->ga_data) + i;
|
||||||
int actual_char_pos = 0;
|
int_u actual_char_pos = 0;
|
||||||
char_u *temp_ptr = text;
|
char_u *temp_ptr = text;
|
||||||
while (temp_ptr < ptr)
|
while (temp_ptr < ptr)
|
||||||
{
|
{
|
||||||
|
110
src/search.c
110
src/search.c
@ -5101,115 +5101,39 @@ fuzzy_match_str_with_pos(char_u *str UNUSED, char_u *pat UNUSED)
|
|||||||
{
|
{
|
||||||
#ifdef FEAT_SEARCH_EXTRA
|
#ifdef FEAT_SEARCH_EXTRA
|
||||||
int score = 0;
|
int score = 0;
|
||||||
garray_T *match_positions = ALLOC_ONE(garray_T);
|
garray_T *match_positions = NULL;
|
||||||
typval_T tv_str;
|
int_u matches[MAX_FUZZY_MATCHES];
|
||||||
list_T *l = NULL;
|
int j = 0;
|
||||||
list_T *retlist = NULL;
|
|
||||||
list_T *match_str_list = NULL;
|
|
||||||
list_T *match_pos_list = NULL;
|
|
||||||
list_T *match_score_list = NULL;
|
|
||||||
listitem_T *score_item = NULL;
|
|
||||||
listitem_T *positions_item = NULL;
|
|
||||||
list_T *positions_outer_list = NULL;
|
|
||||||
listitem_T *outer_li = NULL;
|
|
||||||
list_T *positions_inner_list = NULL;
|
|
||||||
|
|
||||||
|
if (str == NULL || pat == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
match_positions = ALLOC_ONE(garray_T);
|
||||||
if (match_positions == NULL)
|
if (match_positions == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
ga_init2(match_positions, sizeof(int), 10);
|
ga_init2(match_positions, sizeof(int_u), 10);
|
||||||
if (str == NULL || pat == NULL)
|
|
||||||
{
|
if (!fuzzy_match(str, pat, FALSE, &score, matches, MAX_FUZZY_MATCHES)
|
||||||
ga_clear(match_positions);
|
|| score == 0)
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
l = list_alloc();
|
|
||||||
if (l == NULL)
|
|
||||||
{
|
{
|
||||||
ga_clear(match_positions);
|
ga_clear(match_positions);
|
||||||
|
vim_free(match_positions);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tv_str.v_type = VAR_STRING;
|
for (char_u *p = pat; *p != NUL; MB_PTR_ADV(p))
|
||||||
tv_str.vval.v_string = vim_strsave(str);
|
|
||||||
if (tv_str.vval.v_string == NULL || list_append_tv(l, &tv_str) == FAIL)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
retlist = list_alloc();
|
|
||||||
if (retlist == NULL)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
match_str_list = list_alloc();
|
|
||||||
match_pos_list = list_alloc();
|
|
||||||
match_score_list = list_alloc();
|
|
||||||
if (match_str_list == NULL || match_pos_list == NULL || match_score_list == NULL)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
list_append_list(retlist, match_str_list);
|
|
||||||
list_append_list(retlist, match_pos_list);
|
|
||||||
list_append_list(retlist, match_score_list);
|
|
||||||
|
|
||||||
fuzzy_match_in_list(l, pat, FALSE, NULL, NULL, TRUE, retlist, 1);
|
|
||||||
|
|
||||||
if (retlist->lv_len != 3)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
score_item = list_find(retlist, 2);
|
|
||||||
if (score_item != NULL && score_item->li_tv.v_type == VAR_LIST)
|
|
||||||
{
|
{
|
||||||
list_T *score_list = score_item->li_tv.vval.v_list;
|
if (!VIM_ISWHITE(PTR2CHAR(p)))
|
||||||
if (score_list->lv_len > 0)
|
|
||||||
{
|
{
|
||||||
listitem_T *first_score_item = score_list->lv_first;
|
|
||||||
if (first_score_item != NULL && first_score_item->li_tv.v_type == VAR_NUMBER)
|
|
||||||
score = first_score_item->li_tv.vval.v_number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (score == 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
positions_item = list_find(retlist, 1);
|
|
||||||
if (positions_item != NULL && positions_item->li_tv.v_type == VAR_LIST)
|
|
||||||
{
|
|
||||||
positions_outer_list = positions_item->li_tv.vval.v_list;
|
|
||||||
if (positions_outer_list->lv_len > 0)
|
|
||||||
{
|
|
||||||
outer_li = positions_outer_list->lv_first;
|
|
||||||
if (outer_li != NULL && outer_li->li_tv.v_type == VAR_LIST)
|
|
||||||
{
|
|
||||||
positions_inner_list = outer_li->li_tv.vval.v_list;
|
|
||||||
for (listitem_T *li = positions_inner_list->lv_first; li != NULL; li = li->li_next)
|
|
||||||
{
|
|
||||||
if (li->li_tv.v_type == VAR_NUMBER)
|
|
||||||
{
|
|
||||||
int pos = li->li_tv.vval.v_number;
|
|
||||||
ga_grow(match_positions, 1);
|
ga_grow(match_positions, 1);
|
||||||
((int *)match_positions->ga_data)[match_positions->ga_len] = pos;
|
((int_u *)match_positions->ga_data)[match_positions->ga_len] =
|
||||||
|
matches[j];
|
||||||
match_positions->ga_len++;
|
match_positions->ga_len++;
|
||||||
}
|
j++;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vim_free(tv_str.vval.v_string);
|
|
||||||
list_free(retlist);
|
|
||||||
list_free(l);
|
|
||||||
return match_positions;
|
return match_positions;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
vim_free(tv_str.vval.v_string);
|
|
||||||
if (match_str_list != NULL)
|
|
||||||
list_free(match_str_list);
|
|
||||||
if (match_pos_list != NULL)
|
|
||||||
list_free(match_pos_list);
|
|
||||||
if (match_score_list != NULL)
|
|
||||||
list_free(match_score_list);
|
|
||||||
if (retlist != NULL)
|
|
||||||
list_free(retlist);
|
|
||||||
if (l != NULL)
|
|
||||||
list_free(l);
|
|
||||||
ga_clear(match_positions);
|
|
||||||
return NULL;
|
|
||||||
#else
|
#else
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -704,6 +704,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 */
|
||||||
|
/**/
|
||||||
|
479,
|
||||||
/**/
|
/**/
|
||||||
478,
|
478,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user