diff options
author | Billy Su <g4691821@gmail.com> | 2019-03-03 23:55:44 +0800 |
---|---|---|
committer | Billy Su <g4691821@gmail.com> | 2019-03-08 00:06:28 +0800 |
commit | 0a471e009a1410a822384321dbd48a36b0117c5c (patch) | |
tree | 6b0975eb189ebe23fd12fafb5e9d6d432070e214 | |
parent | fbd8209286373843b7e9b4151a1432fc4555484d (diff) | |
download | rneovim-0a471e009a1410a822384321dbd48a36b0117c5c.tar.gz rneovim-0a471e009a1410a822384321dbd48a36b0117c5c.tar.bz2 rneovim-0a471e009a1410a822384321dbd48a36b0117c5c.zip |
vim-patch:8.0.0646: the hlsearch test fails on fast systems
Problem: The hlsearch test fails on fast systems.
Solution: Make the search pattern slower. Fix that the old regexp engine
doesn't timeout properly.
https://github.com/vim/vim/commit/0946326580e6f034fe2c88d041407ea0fde980ab
-rw-r--r-- | src/nvim/regexp.c | 30 | ||||
-rw-r--r-- | src/nvim/testdir/test_hlsearch.vim | 5 |
2 files changed, 25 insertions, 10 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 396b376e39..dc3fbbaeb5 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3496,7 +3496,7 @@ static long bt_regexec_both(char_u *line, && (utf_fold(prog->regstart) == utf_fold(c) || (c < 255 && prog->regstart < 255 && mb_tolower(prog->regstart) == mb_tolower(c))))) { - retval = regtry(prog, col); + retval = regtry(prog, col, tm, timed_out); } else { retval = 0; } @@ -3520,9 +3520,10 @@ static long bt_regexec_both(char_u *line, break; } - retval = regtry(prog, col); - if (retval > 0) + retval = regtry(prog, col, tm, timed_out); + if (retval > 0) { break; + } /* if not currently on the first line, get it again */ if (reglnum != 0) { @@ -3603,7 +3604,8 @@ void unref_extmatch(reg_extmatch_T *em) * regtry - try match of "prog" with at regline["col"]. * Returns 0 for failure, number of lines contained in the match otherwise. */ -static long regtry(bt_regprog_T *prog, colnr_T col) +static long regtry(bt_regprog_T *prog, colnr_T col, + proftime_T *tm, int *timed_out) { reginput = regline + col; need_clear_subexpr = TRUE; @@ -3611,8 +3613,9 @@ static long regtry(bt_regprog_T *prog, colnr_T col) if (prog->reghasz == REX_SET) need_clear_zsubexpr = TRUE; - if (regmatch(prog->program + 1) == 0) + if (regmatch(prog->program + 1, tm, timed_out) == 0) { return 0; + } cleanup_subexpr(); if (REG_MULTI) { @@ -3768,9 +3771,11 @@ static long bl_maxval; * Returns FALSE when there is no match. Leaves reginput and reglnum in an * undefined state! */ -static int -regmatch ( - char_u *scan /* Current node. */ +static int +regmatch( + char_u *scan, // Current node. + proftime_T *tm, + int *timed_out ) { char_u *next; /* Next node. */ @@ -3779,12 +3784,14 @@ regmatch ( regitem_T *rp; int no; int status; /* one of the RA_ values: */ + int tm_count; /* counter for checking timeout */ #define RA_FAIL 1 /* something failed, abort */ #define RA_CONT 2 /* continue in inner loop */ #define RA_BREAK 3 /* break inner loop */ #define RA_MATCH 4 /* successful match */ #define RA_NOMATCH 5 /* didn't match */ + tm_count = 0; /* Make "regstack" and "backpos" empty. They are allocated and freed in * bt_regexec_both() to reduce malloc()/free() calls. */ regstack.ga_len = 0; @@ -3814,6 +3821,13 @@ regmatch ( status = RA_FAIL; break; } + if (tm != NULL && ++tm_count == 100) { + tm_count = 0; + if (profile_passed_limit(*tm)) { + status = RA_FAIL; + break; + } + } status = RA_CONT; #ifdef REGEXP_DEBUG diff --git a/src/nvim/testdir/test_hlsearch.vim b/src/nvim/testdir/test_hlsearch.vim index 18c4cb37b4..97f6ae7b51 100644 --- a/src/nvim/testdir/test_hlsearch.vim +++ b/src/nvim/testdir/test_hlsearch.vim @@ -38,7 +38,8 @@ func Test_hlsearch_hangs() endif " This pattern takes a long time to match, it should timeout. - help + new + call setline(1, ['aaa', repeat('abc ', 100000), 'ccc']) let start = reltime() set hlsearch nolazyredraw redrawtime=101 let @/ = '\%#=1a*.*X\@<=b*' @@ -47,7 +48,7 @@ func Test_hlsearch_hangs() call assert_true(elapsed > 0.1) call assert_true(elapsed < 1.0) set nohlsearch redrawtime& - quit + bwipe! endfunc func Test_hlsearch_eol_highlight() |