aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/regexp_nfa.c46
-rw-r--r--src/nvim/version.c2
2 files changed, 30 insertions, 18 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);
}
diff --git a/src/nvim/version.c b/src/nvim/version.c
index e07c4a242a..e8edfdb5b1 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -1064,7 +1064,7 @@ static int included_patches[] = {
616,
615,
614,
- // 613,
+ 613,
612,
// 611 NA
// 610 NA