Skip to content

Commit 5ea38d1

Browse files
committed
patch 8.2.5114: time limit on searchpair() does not work properly
Problem: Time limit on searchpair() does not work properly. Solution: Set the time limit once instead of for each regexp. (closes #10562)
1 parent c72e31d commit 5ea38d1

4 files changed

Lines changed: 42 additions & 11 deletions

File tree

src/evalfunc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8975,6 +8975,10 @@ do_searchpair(
89758975
if (skip != NULL)
89768976
use_skip = eval_expr_valid_arg(skip);
89778977

8978+
#ifdef FEAT_RELTIME
8979+
if (time_limit > 0)
8980+
init_regexp_timeout(time_limit);
8981+
#endif
89788982
save_cursor = curwin->w_cursor;
89798983
pos = curwin->w_cursor;
89808984
CLEAR_POS(&firstpos);
@@ -8986,9 +8990,6 @@ do_searchpair(
89868990

89878991
CLEAR_FIELD(sia);
89888992
sia.sa_stop_lnum = lnum_stop;
8989-
#ifdef FEAT_RELTIME
8990-
sia.sa_tm = time_limit;
8991-
#endif
89928993
n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L,
89938994
options, RE_SEARCH, &sia);
89948995
if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos)))
@@ -9074,6 +9075,9 @@ do_searchpair(
90749075
curwin->w_cursor = save_cursor;
90759076

90769077
theend:
9078+
#ifdef FEAT_RELTIME
9079+
disable_regexp_timeout();
9080+
#endif
90779081
vim_free(pat2);
90789082
vim_free(pat3);
90799083
if (p_cpo == empty_option)

src/search.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,10 @@ searchit(
674674
stop_lnum = extra_arg->sa_stop_lnum;
675675
#ifdef FEAT_RELTIME
676676
if (extra_arg->sa_tm > 0)
677-
{
678677
init_regexp_timeout(extra_arg->sa_tm);
679-
timed_out = &extra_arg->sa_timed_out;
680-
}
678+
// Also set the pointer when sa_tm is zero, the caller may have set the
679+
// timeout.
680+
timed_out = &extra_arg->sa_timed_out;
681681
#endif
682682
}
683683

@@ -1105,9 +1105,10 @@ searchit(
11051105
}
11061106
while (--count > 0 && found); // stop after count matches or no match
11071107

1108-
# ifdef FEAT_RELTIME
1109-
disable_regexp_timeout();
1110-
# endif
1108+
#ifdef FEAT_RELTIME
1109+
if (extra_arg != NULL && extra_arg->sa_tm > 0)
1110+
disable_regexp_timeout();
1111+
#endif
11111112
vim_regfree(regmatch.regprog);
11121113

11131114
if (!found) // did not find it
@@ -4859,7 +4860,7 @@ do_fuzzymatch(typval_T *argvars, typval_T *rettv, int retmatchpos)
48594860

48604861
// get the fuzzy matches
48614862
ret = rettv_list_alloc(rettv);
4862-
if (ret != OK)
4863+
if (ret == FAIL)
48634864
goto done;
48644865
if (retmatchpos)
48654866
{

src/testdir/test_search.vim

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,31 @@ func Test_searchpair()
328328
call assert_equal(3, searchpair('\<if\>', '\<else\>', '\<endif\>', 'W'))
329329
call assert_equal([0, 3, 3, 0], getpos('.'))
330330

331-
q!
331+
bwipe!
332+
endfunc
333+
334+
func Test_searchpair_timeout()
335+
CheckFeature reltime
336+
337+
func Waitabit()
338+
sleep 20m
339+
return 1 " skip match
340+
endfunc
341+
342+
new
343+
call setline(1, range(100))
344+
call setline(1, "(start here")
345+
call setline(100, "end here)")
346+
let starttime = reltime()
347+
348+
" A timeout of 100 msec should happen after about five times of 20 msec wait
349+
" in Waitabit(). When the timeout applies to each search the elapsed time
350+
" will be much longer.
351+
call assert_equal(0, searchpair('(', '\d', ')', '', "Waitabit()", 0, 100))
352+
let elapsed = reltime(starttime)->reltimefloat()
353+
call assert_inrange(0.09, 0.300, elapsed)
354+
355+
bwipe!
332356
endfunc
333357

334358
func Test_searchpairpos()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
5114,
737739
/**/
738740
5113,
739741
/**/

0 commit comments

Comments
 (0)