diff options
author | James McCoy <jamessan@jamessan.com> | 2016-04-21 22:13:32 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2016-04-25 06:36:08 -0400 |
commit | ee9cca892c6dfe3eb9afd763e3cc288b99053466 (patch) | |
tree | b8ca1579865c31682e5b6e9c6181e45e5db68af8 /src/nvim/regexp_nfa.c | |
parent | ef205c3851fda637af49b5517bee60e6a62275ed (diff) | |
download | rneovim-ee9cca892c6dfe3eb9afd763e3cc288b99053466.tar.gz rneovim-ee9cca892c6dfe3eb9afd763e3cc288b99053466.tar.bz2 rneovim-ee9cca892c6dfe3eb9afd763e3cc288b99053466.zip |
vim-patch:7.4.613
Problem: The NFA engine does not implement the 'redrawtime' time limit.
Solution: Implement the time limit.
https://github.com/vim/vim/commit/70781ee4035b5fd5e3cbb3fe4c7646e19119f0a8
Diffstat (limited to 'src/nvim/regexp_nfa.c')
-rw-r--r-- | src/nvim/regexp_nfa.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index e2849fb17a..e66f2681bf 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -3466,7 +3466,8 @@ static char *pim_info(nfa_pim_T *pim) /* Used during execution: whether a match has been found. */ static int nfa_match; - +static proftime_T *nfa_time_limit; +static int nfa_time_count; /* * Copy postponed invisible match info from "from" to "to". @@ -4853,6 +4854,9 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm fast_breakcheck(); if (got_int) return FALSE; + if (nfa_time_limit != NULL && profile_passed_limit(*nfa_time_limit)) { + return FALSE; + } nfa_match = FALSE; @@ -6071,10 +6075,17 @@ nextchar: break; // Allow interrupting with CTRL-C. - fast_breakcheck(); + line_breakcheck(); if (got_int) { break; } + // Check for timeout once every twenty times to avoid overhead. + if (nfa_time_limit != NULL && ++nfa_time_count == 20) { + nfa_time_count = 0; + if (profile_passed_limit(*nfa_time_limit)) { + break; + } + } } #ifdef REGEXP_DEBUG @@ -6100,7 +6111,7 @@ theend: * Try match of "prog" with at regline["col"]. * Returns <= 0 for failure, number of lines contained in the match otherwise. */ -static long nfa_regtry(nfa_regprog_T *prog, colnr_T col) +static long nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm) { int i; regsubs_T subs, m; @@ -6110,6 +6121,8 @@ static long nfa_regtry(nfa_regprog_T *prog, colnr_T col) #endif reginput = regline + col; + nfa_time_limit = tm; + nfa_time_count = 0; #ifdef REGEXP_DEBUG f = fopen(NFA_REGEXP_RUN_LOG, "a"); @@ -6207,17 +6220,16 @@ static long nfa_regtry(nfa_regprog_T *prog, colnr_T col) return 1 + reglnum; } -/* - * Match a regexp against a string ("line" points to the string) or multiple - * lines ("line" is NULL, use reg_getline()). - * - * Returns <= 0 for failure, number of lines contained in the match otherwise. - */ -static long -nfa_regexec_both ( - char_u *line, - colnr_T startcol /* column to start looking for match */ -) +/// Match a regexp against a string ("line" points to the string) or multiple +/// lines ("line" is NULL, use reg_getline()). +/// +/// @param line String in which to search or NULL +/// @param startcol Column to start looking for match +/// @param tm Timeout limit or NULL +/// +/// @return <= 0 if there is no match and number of lines contained in the +/// match otherwise. +static long nfa_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm) { nfa_regprog_T *prog; long retval = 0L; @@ -6297,7 +6309,7 @@ nfa_regexec_both ( prog->state[i].lastlist[1] = 0; } - retval = nfa_regtry(prog, col); + retval = nfa_regtry(prog, col, tm); nfa_regengine.expr = NULL; @@ -6449,7 +6461,7 @@ nfa_regexec_nl ( ireg_ic = rmp->rm_ic; ireg_icombine = FALSE; ireg_maxcol = 0; - return nfa_regexec_both(line, col); + return nfa_regexec_both(line, col, NULL); } /// Matches a regexp against multiple lines. @@ -6500,5 +6512,5 @@ static long nfa_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, ireg_icombine = FALSE; ireg_maxcol = rmp->rmm_maxcol; - return nfa_regexec_both(NULL, col); + return nfa_regexec_both(NULL, col, tm); } |