summaryrefslogtreecommitdiff
path: root/src/regexp_nfa.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-27 15:35:28 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-27 15:35:28 +0100
commit02e8d4e4ffcdd6ee919e19692d591da8e18a565d (patch)
treec8c1beb22eaee3ccfece6beb09c0620b20f5b80f /src/regexp_nfa.c
parentbf79a4e48d09a5ae08645592885d54230fed30b8 (diff)
downloadvim-git-02e8d4e4ffcdd6ee919e19692d591da8e18a565d.tar.gz
patch 8.2.5028: syntax regexp matching can be slowv8.2.5028
Problem: Syntax regexp matching can be slow. Solution: Adjust the counters for checking the timeout to check about once per msec. (closes #10487, closes #2712)
Diffstat (limited to 'src/regexp_nfa.c')
-rw-r--r--src/regexp_nfa.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index 511b90483..1e7cd9b46 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -5649,11 +5649,27 @@ find_match_text(colnr_T startcol, int regstart, char_u *match_text)
static int
nfa_did_time_out()
{
- if (nfa_time_limit != NULL && profile_passed_limit(nfa_time_limit))
+ static int tm_count = 0;
+
+ // Check for timeout once in 800 times to avoid excessive overhead from
+ // reading the clock. The value has been picked to check about once per
+ // msec on a modern CPU.
+ if (nfa_time_limit != NULL)
{
- if (nfa_timed_out != NULL)
- *nfa_timed_out = TRUE;
- return TRUE;
+ if (tm_count == 800)
+ {
+ if (profile_passed_limit(nfa_time_limit))
+ {
+ if (nfa_timed_out != NULL)
+ *nfa_timed_out = TRUE;
+ return TRUE;
+ }
+ // Only reset the count when not timed out, so that when it did
+ // timeout it keeps timing out until the time limit is changed.
+ tm_count = 0;
+ }
+ else
+ ++tm_count;
}
return FALSE;
}