patch 8.2.5028: syntax regexp matching can be slow

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)
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index 511b904..1e7cd9b 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -5649,11 +5649,27 @@
     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;
 }