@@ -3492,7 +3492,7 @@ typedef struct regbehind_S
34923492
34933493static char_u * reg_getline (linenr_T lnum );
34943494static long bt_regexec_both (char_u * line , colnr_T col , proftime_T * tm , int * timed_out );
3495- static long regtry (bt_regprog_T * prog , colnr_T col );
3495+ static long regtry (bt_regprog_T * prog , colnr_T col , proftime_T * tm , int * timed_out );
34963496static void cleanup_subexpr (void );
34973497#ifdef FEAT_SYN_HL
34983498static void cleanup_zsubexpr (void );
@@ -3519,7 +3519,7 @@ static void save_se_one(save_se_T *savep, char_u **pp);
35193519
35203520static int re_num_cmp (long_u val , char_u * scan );
35213521static int match_with_backref (linenr_T start_lnum , colnr_T start_col , linenr_T end_lnum , colnr_T end_col , int * bytelen );
3522- static int regmatch (char_u * prog );
3522+ static int regmatch (char_u * prog , proftime_T * tm , int * timed_out );
35233523static int regrepeat (char_u * p , long maxcount );
35243524
35253525#ifdef DEBUG
@@ -3780,8 +3780,8 @@ bt_regexec_multi(
37803780bt_regexec_both (
37813781 char_u * line ,
37823782 colnr_T col , /* column to start looking for match */
3783- proftime_T * tm UNUSED , /* timeout limit or NULL */
3784- int * timed_out UNUSED ) /* flag set on timeout or NULL */
3783+ proftime_T * tm , /* timeout limit or NULL */
3784+ int * timed_out ) /* flag set on timeout or NULL */
37853785{
37863786 bt_regprog_T * prog ;
37873787 char_u * s ;
@@ -3919,7 +3919,7 @@ bt_regexec_both(
39193919 || (c < 255 && prog -> regstart < 255 &&
39203920#endif
39213921 MB_TOLOWER (prog -> regstart ) == MB_TOLOWER (c )))))
3922- retval = regtry (prog , col );
3922+ retval = regtry (prog , col , tm , timed_out );
39233923 else
39243924 retval = 0 ;
39253925 }
@@ -3958,7 +3958,7 @@ bt_regexec_both(
39583958 break ;
39593959 }
39603960
3961- retval = regtry (prog , col );
3961+ retval = regtry (prog , col , tm , timed_out );
39623962 if (retval > 0 )
39633963 break ;
39643964
@@ -4059,7 +4059,11 @@ unref_extmatch(reg_extmatch_T *em)
40594059 * Returns 0 for failure, number of lines contained in the match otherwise.
40604060 */
40614061 static long
4062- regtry (bt_regprog_T * prog , colnr_T col )
4062+ regtry (
4063+ bt_regprog_T * prog ,
4064+ colnr_T col ,
4065+ proftime_T * tm , /* timeout limit or NULL */
4066+ int * timed_out ) /* flag set on timeout or NULL */
40634067{
40644068 reginput = regline + col ;
40654069 need_clear_subexpr = TRUE;
@@ -4069,7 +4073,7 @@ regtry(bt_regprog_T *prog, colnr_T col)
40694073 need_clear_zsubexpr = TRUE;
40704074#endif
40714075
4072- if (regmatch (prog -> program + 1 ) == 0 )
4076+ if (regmatch (prog -> program + 1 , tm , timed_out ) == 0 )
40734077 return 0 ;
40744078
40754079 cleanup_subexpr ();
@@ -4253,7 +4257,9 @@ static long bl_maxval;
42534257 */
42544258 static int
42554259regmatch (
4256- char_u * scan ) /* Current node. */
4260+ char_u * scan , /* Current node. */
4261+ proftime_T * tm UNUSED , /* timeout limit or NULL */
4262+ int * timed_out UNUSED ) /* flag set on timeout or NULL */
42574263{
42584264 char_u * next ; /* Next node. */
42594265 int op ;
@@ -4266,6 +4272,9 @@ regmatch(
42664272#define RA_BREAK 3 /* break inner loop */
42674273#define RA_MATCH 4 /* successful match */
42684274#define RA_NOMATCH 5 /* didn't match */
4275+ #ifdef FEAT_RELTIME
4276+ int tm_count = 0 ;
4277+ #endif
42694278
42704279 /* Make "regstack" and "backpos" empty. They are allocated and freed in
42714280 * bt_regexec_both() to reduce malloc()/free() calls. */
@@ -4300,6 +4309,20 @@ regmatch(
43004309 status = RA_FAIL ;
43014310 break ;
43024311 }
4312+ #ifdef FEAT_RELTIME
4313+ /* Check for timeout once in a 100 times to avoid overhead. */
4314+ if (tm != NULL && ++ tm_count == 100 )
4315+ {
4316+ tm_count = 0 ;
4317+ if (profile_passed_limit (tm ))
4318+ {
4319+ if (timed_out != NULL )
4320+ * timed_out = TRUE;
4321+ status = RA_FAIL ;
4322+ break ;
4323+ }
4324+ }
4325+ #endif
43034326 status = RA_CONT ;
43044327
43054328#ifdef DEBUG
0 commit comments