@@ -3492,7 +3492,7 @@ typedef struct regbehind_S
3492
3492
3493
3493
static char_u * reg_getline (linenr_T lnum );
3494
3494
static 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 );
3496
3496
static void cleanup_subexpr (void );
3497
3497
#ifdef FEAT_SYN_HL
3498
3498
static void cleanup_zsubexpr (void );
@@ -3519,7 +3519,7 @@ static void save_se_one(save_se_T *savep, char_u **pp);
3519
3519
3520
3520
static int re_num_cmp (long_u val , char_u * scan );
3521
3521
static 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 );
3523
3523
static int regrepeat (char_u * p , long maxcount );
3524
3524
3525
3525
#ifdef DEBUG
@@ -3780,8 +3780,8 @@ bt_regexec_multi(
3780
3780
bt_regexec_both (
3781
3781
char_u * line ,
3782
3782
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 */
3785
3785
{
3786
3786
bt_regprog_T * prog ;
3787
3787
char_u * s ;
@@ -3919,7 +3919,7 @@ bt_regexec_both(
3919
3919
|| (c < 255 && prog -> regstart < 255 &&
3920
3920
#endif
3921
3921
MB_TOLOWER (prog -> regstart ) == MB_TOLOWER (c )))))
3922
- retval = regtry (prog , col );
3922
+ retval = regtry (prog , col , tm , timed_out );
3923
3923
else
3924
3924
retval = 0 ;
3925
3925
}
@@ -3958,7 +3958,7 @@ bt_regexec_both(
3958
3958
break ;
3959
3959
}
3960
3960
3961
- retval = regtry (prog , col );
3961
+ retval = regtry (prog , col , tm , timed_out );
3962
3962
if (retval > 0 )
3963
3963
break ;
3964
3964
@@ -4059,7 +4059,11 @@ unref_extmatch(reg_extmatch_T *em)
4059
4059
* Returns 0 for failure, number of lines contained in the match otherwise.
4060
4060
*/
4061
4061
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 */
4063
4067
{
4064
4068
reginput = regline + col ;
4065
4069
need_clear_subexpr = TRUE;
@@ -4069,7 +4073,7 @@ regtry(bt_regprog_T *prog, colnr_T col)
4069
4073
need_clear_zsubexpr = TRUE;
4070
4074
#endif
4071
4075
4072
- if (regmatch (prog -> program + 1 ) == 0 )
4076
+ if (regmatch (prog -> program + 1 , tm , timed_out ) == 0 )
4073
4077
return 0 ;
4074
4078
4075
4079
cleanup_subexpr ();
@@ -4253,7 +4257,9 @@ static long bl_maxval;
4253
4257
*/
4254
4258
static int
4255
4259
regmatch (
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 */
4257
4263
{
4258
4264
char_u * next ; /* Next node. */
4259
4265
int op ;
@@ -4266,6 +4272,9 @@ regmatch(
4266
4272
#define RA_BREAK 3 /* break inner loop */
4267
4273
#define RA_MATCH 4 /* successful match */
4268
4274
#define RA_NOMATCH 5 /* didn't match */
4275
+ #ifdef FEAT_RELTIME
4276
+ int tm_count = 0 ;
4277
+ #endif
4269
4278
4270
4279
/* Make "regstack" and "backpos" empty. They are allocated and freed in
4271
4280
* bt_regexec_both() to reduce malloc()/free() calls. */
@@ -4300,6 +4309,20 @@ regmatch(
4300
4309
status = RA_FAIL ;
4301
4310
break ;
4302
4311
}
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
4303
4326
status = RA_CONT ;
4304
4327
4305
4328
#ifdef DEBUG
0 commit comments