Skip to content

Commit fbd0b0a

Browse files
committed
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Problem: When 'hlsearch' is set and matching with the last search pattern is very slow, Vim becomes unusable. Cannot quit search by pressing CTRL-C. Solution: When the search times out set a flag and don't try again. Check for timeout and CTRL-C in NFA loop that adds states.
1 parent 8cf9128 commit fbd0b0a

File tree

19 files changed

+123
-67
lines changed

19 files changed

+123
-67
lines changed

src/edit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4512,7 +4512,7 @@ ins_compl_get_exp(pos_T *ini)
45124512
found_new_match = searchit(NULL, ins_buf, pos,
45134513
compl_direction,
45144514
compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
4515-
RE_LAST, (linenr_T)0, NULL);
4515+
RE_LAST, (linenr_T)0, NULL, NULL);
45164516
--msg_silent;
45174517
if (!compl_started || set_match_pos)
45184518
{

src/evalfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9281,7 +9281,7 @@ search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp)
92819281

92829282
pos = save_cursor = curwin->w_cursor;
92839283
subpatnum = searchit(curwin, curbuf, &pos, dir, pat, 1L,
9284-
options, RE_SEARCH, (linenr_T)lnum_stop, &tm);
9284+
options, RE_SEARCH, (linenr_T)lnum_stop, &tm, NULL);
92859285
if (subpatnum != FAIL)
92869286
{
92879287
if (flags & SP_SUBPAT)
@@ -9619,7 +9619,7 @@ do_searchpair(
96199619
for (;;)
96209620
{
96219621
n = searchit(curwin, curbuf, &pos, dir, pat, 1L,
9622-
options, RE_SEARCH, lnum_stop, &tm);
9622+
options, RE_SEARCH, lnum_stop, &tm, NULL);
96239623
if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos)))
96249624
/* didn't find it or found the first match again: FAIL */
96259625
break;

src/ex_cmds.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,7 +5096,7 @@ do_sub(exarg_T *eap)
50965096
); ++lnum)
50975097
{
50985098
nmatch = vim_regexec_multi(&regmatch, curwin, curbuf, lnum,
5099-
(colnr_T)0, NULL);
5099+
(colnr_T)0, NULL, NULL);
51005100
if (nmatch)
51015101
{
51025102
colnr_T copycol;
@@ -5695,7 +5695,7 @@ do_sub(exarg_T *eap)
56955695
|| nmatch_tl > 0
56965696
|| (nmatch = vim_regexec_multi(&regmatch, curwin,
56975697
curbuf, sub_firstlnum,
5698-
matchcol, NULL)) == 0
5698+
matchcol, NULL, NULL)) == 0
56995699
|| regmatch.startpos[0].lnum > 0)
57005700
{
57015701
if (new_start != NULL)
@@ -5760,7 +5760,7 @@ do_sub(exarg_T *eap)
57605760
}
57615761
if (nmatch == -1 && !lastone)
57625762
nmatch = vim_regexec_multi(&regmatch, curwin, curbuf,
5763-
sub_firstlnum, matchcol, NULL);
5763+
sub_firstlnum, matchcol, NULL, NULL);
57645764

57655765
/*
57665766
* 5. break if there isn't another match in this line
@@ -6012,7 +6012,7 @@ ex_global(exarg_T *eap)
60126012
{
60136013
lnum = curwin->w_cursor.lnum;
60146014
match = vim_regexec_multi(&regmatch, curwin, curbuf, lnum,
6015-
(colnr_T)0, NULL);
6015+
(colnr_T)0, NULL, NULL);
60166016
if ((type == 'g' && match) || (type == 'v' && !match))
60176017
global_exe_one(cmd, lnum);
60186018
}
@@ -6025,7 +6025,7 @@ ex_global(exarg_T *eap)
60256025
{
60266026
/* a match on this line? */
60276027
match = vim_regexec_multi(&regmatch, curwin, curbuf, lnum,
6028-
(colnr_T)0, NULL);
6028+
(colnr_T)0, NULL, NULL);
60296029
if ((type == 'g' && match) || (type == 'v' && !match))
60306030
{
60316031
ml_setmarked(lnum);

src/ex_docmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,7 +4556,7 @@ get_address(
45564556
curwin->w_cursor.col = 0;
45574557
searchcmdlen = 0;
45584558
if (!do_search(NULL, c, cmd, 1L,
4559-
SEARCH_HIS | SEARCH_MSG, NULL))
4559+
SEARCH_HIS | SEARCH_MSG, NULL, NULL))
45604560
{
45614561
curwin->w_cursor = pos;
45624562
cmd = NULL;
@@ -4613,7 +4613,7 @@ get_address(
46134613
if (searchit(curwin, curbuf, &pos,
46144614
*cmd == '?' ? BACKWARD : FORWARD,
46154615
(char_u *)"", 1L, SEARCH_MSG,
4616-
i, (linenr_T)0, NULL) != FAIL)
4616+
i, (linenr_T)0, NULL, NULL) != FAIL)
46174617
lnum = pos.lnum;
46184618
else
46194619
{

src/ex_getln.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ getcmdline(
16931693
i = searchit(curwin, curbuf, &t,
16941694
c == Ctrl_G ? FORWARD : BACKWARD,
16951695
ccline.cmdbuff, count, search_flags,
1696-
RE_SEARCH, 0, NULL);
1696+
RE_SEARCH, 0, NULL, NULL);
16971697
--emsg_off;
16981698
if (i)
16991699
{
@@ -1903,9 +1903,9 @@ getcmdline(
19031903
i = do_search(NULL, firstc, ccline.cmdbuff, count,
19041904
SEARCH_KEEP + SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK,
19051905
#ifdef FEAT_RELTIME
1906-
&tm
1906+
&tm, NULL
19071907
#else
1908-
NULL
1908+
NULL, NULL
19091909
#endif
19101910
);
19111911
--emsg_off;

src/gui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5361,7 +5361,7 @@ gui_do_findrepl(
53615361
searchflags += SEARCH_START;
53625362
i = msg_scroll;
53635363
(void)do_search(NULL, down ? '/' : '?', ga.ga_data, 1L,
5364-
searchflags, NULL);
5364+
searchflags, NULL, NULL);
53655365
msg_scroll = i; /* don't let an error message set msg_scroll */
53665366
}
53675367

src/normal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,7 +4358,7 @@ find_decl(
43584358
{
43594359
valid = FALSE;
43604360
t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD,
4361-
pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL);
4361+
pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL);
43624362
if (curwin->w_cursor.lnum >= old_pos.lnum)
43634363
t = FAIL; /* match after start is failure too */
43644364

@@ -6380,7 +6380,7 @@ normal_search(
63806380
curwin->w_set_curswant = TRUE;
63816381

63826382
i = do_search(cap->oap, dir, pat, cap->count1,
6383-
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL);
6383+
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL);
63846384
if (i == 0)
63856385
clearop(cap->oap);
63866386
else

src/proto/regexp.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ void vim_regfree(regprog_T *prog);
1616
int vim_regexec_prog(regprog_T **prog, int ignore_case, char_u *line, colnr_T col);
1717
int vim_regexec(regmatch_T *rmp, char_u *line, colnr_T col);
1818
int vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col);
19-
long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm);
19+
long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm, int *timed_out);
2020
/* vim: set ft=c : */

src/proto/search.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ char_u *last_search_pat(void);
1919
void reset_search_dir(void);
2020
void set_last_search_pat(char_u *s, int idx, int magic, int setlast);
2121
void last_pat_prog(regmmatch_T *regmatch);
22-
int searchit(win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum, proftime_T *tm);
22+
int searchit(win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum, proftime_T *tm, int *timed_out);
2323
void set_search_direction(int cdir);
24-
int do_search(oparg_T *oap, int dirc, char_u *pat, long count, int options, proftime_T *tm);
24+
int do_search(oparg_T *oap, int dirc, char_u *pat, long count, int options, proftime_T *tm, int *timed_out);
2525
int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat);
2626
int searchc(cmdarg_T *cap, int t_cmd);
2727
pos_T *findmatch(oparg_T *oap, int initc);

src/quickfix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,7 @@ qf_jump(
24152415
save_cursor = curwin->w_cursor;
24162416
curwin->w_cursor.lnum = 0;
24172417
if (!do_search(NULL, '/', qf_ptr->qf_pattern, (long)1,
2418-
SEARCH_KEEP, NULL))
2418+
SEARCH_KEEP, NULL, NULL))
24192419
curwin->w_cursor = save_cursor;
24202420
}
24212421

@@ -4237,7 +4237,7 @@ ex_vimgrep(exarg_T *eap)
42374237
{
42384238
col = 0;
42394239
while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
4240-
col, NULL) > 0)
4240+
col, NULL, NULL) > 0)
42414241
{
42424242
/* Pass the buffer number so that it gets used even for a
42434243
* dummy buffer, unless duplicate_name is set, then the

0 commit comments

Comments
 (0)