patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Problem: Using gettimeofday() for timeout is very inefficient.
Solution: Set a platform dependent timer. (Paul Ollis, closes #10505)
diff --git a/src/regexp.c b/src/regexp.c
index 4bf137a..3d08d5a 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -20,6 +20,11 @@
# define BT_REGEXP_DEBUG_LOG_NAME "bt_regexp_debug.log"
#endif
+#ifdef FEAT_RELTIME
+static int dummy_timeout_flag = 0;
+static const int *timeout_flag = &dummy_timeout_flag;
+#endif
+
/*
* Magic characters have a special meaning, they don't match literally.
* Magic characters are negative. This separates them from literal characters
@@ -45,6 +50,20 @@
return Magic(x);
}
+#ifdef FEAT_RELTIME
+ void
+init_regexp_timeout(long msec)
+{
+ timeout_flag = start_timeout(msec);
+}
+
+ void
+disable_regexp_timeout(void)
+{
+ stop_timeout();
+}
+#endif
+
/*
* The first byte of the BT regexp internal "program" is actually this magic
* number; the start node begins in the second byte. It's used to catch the
@@ -1944,8 +1963,9 @@
#ifdef FEAT_EVAL
// To make sure that the length doesn't change between checking the
// length and copying the string, and to speed up things, the
- // resulting string is saved from the call with "flags & REGSUB_COPY"
- // == 0 to the // call with "flags & REGSUB_COPY" != 0.
+ // resulting string is saved from the call with
+ // "flags & REGSUB_COPY" == 0 to the call with
+ // "flags & REGSUB_COPY" != 0.
if (copy)
{
if (eval_result != NULL)
@@ -1960,7 +1980,7 @@
int prev_can_f_submatch = can_f_submatch;
regsubmatch_T rsm_save;
- vim_free(eval_result);
+ VIM_CLEAR(eval_result);
// The expression may contain substitute(), which calls us
// recursively. Make sure submatch() gets the text from the first
@@ -2905,7 +2925,6 @@
buf_T *buf, // buffer in which to search
linenr_T lnum, // nr of line to start looking for match
colnr_T col, // column to start looking for match
- proftime_T *tm, // timeout limit or NULL
int *timed_out) // flag is set when timeout limit reached
{
int result;
@@ -2926,7 +2945,7 @@
rex_in_use = TRUE;
result = rmp->regprog->engine->regexec_multi(
- rmp, win, buf, lnum, col, tm, timed_out);
+ rmp, win, buf, lnum, col, timed_out);
rmp->regprog->re_in_use = FALSE;
// NFA engine aborted because it's very slow.
@@ -2966,7 +2985,7 @@
rmp->regprog->re_in_use = TRUE;
result = rmp->regprog->engine->regexec_multi(
- rmp, win, buf, lnum, col, tm, timed_out);
+ rmp, win, buf, lnum, col, timed_out);
rmp->regprog->re_in_use = FALSE;
}
vim_free(pat);