1
0
forked from aniani/vim

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)
This commit is contained in:
Paul Ollis
2022-06-05 16:55:54 +01:00
committed by Bram Moolenaar
parent 1d97db3d98
commit 6574577cac
29 changed files with 811 additions and 242 deletions

View File

@@ -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 @@ toggle_Magic(int x)
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 @@ vim_regsub_both(
#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 @@ vim_regsub_both(
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 @@ vim_regexec_multi(
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 @@ vim_regexec_multi(
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 @@ vim_regexec_multi(
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);