diff options
author | Paul Ollis <paul@cleversheep.org> | 2022-06-05 16:55:54 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-06-05 16:55:54 +0100 |
commit | 6574577cacd393ab7591fc776ea060eebc939e55 (patch) | |
tree | f583ca9957280e7086b8d14ef44127302829fd40 /src/regexp_bt.c | |
parent | 1d97db3d987c05af88c30ad20f537bcf3024f9c1 (diff) | |
download | vim-git-6574577cacd393ab7591fc776ea060eebc939e55.tar.gz |
patch 8.2.5057: using gettimeofday() for timeout is very inefficientv8.2.5057
Problem: Using gettimeofday() for timeout is very inefficient.
Solution: Set a platform dependent timer. (Paul Ollis, closes #10505)
Diffstat (limited to 'src/regexp_bt.c')
-rw-r--r-- | src/regexp_bt.c | 54 |
1 files changed, 15 insertions, 39 deletions
diff --git a/src/regexp_bt.c b/src/regexp_bt.c index 5bf0e0c4e..e307c419b 100644 --- a/src/regexp_bt.c +++ b/src/regexp_bt.c @@ -3228,7 +3228,6 @@ restore_subexpr(regbehind_T *bp) static int regmatch( char_u *scan, // Current node. - proftime_T *tm UNUSED, // timeout limit or NULL int *timed_out UNUSED) // flag set on timeout or NULL { char_u *next; // Next node. @@ -3237,9 +3236,6 @@ regmatch( regitem_T *rp; int no; int status; // one of the RA_ values: -#ifdef FEAT_RELTIME - int tm_count = 0; -#endif // Make "regstack" and "backpos" empty. They are allocated and freed in // bt_regexec_both() to reduce malloc()/free() calls. @@ -3271,19 +3267,12 @@ regmatch( break; } #ifdef FEAT_RELTIME - // Check for timeout once in 250 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 (tm != NULL && ++tm_count == 250) + if (*timeout_flag) { - tm_count = 0; - if (profile_passed_limit(tm)) - { - if (timed_out != NULL) - *timed_out = TRUE; - status = RA_FAIL; - break; - } + if (timed_out != NULL) + *timed_out = TRUE; + status = RA_FAIL; + break; } #endif status = RA_CONT; @@ -3315,7 +3304,7 @@ regmatch( op = OP(scan); // Check for character class with NL added. if (!rex.reg_line_lbr && WITH_NL(op) && REG_MULTI - && *rex.input == NUL && rex.lnum <= rex.reg_maxline) + && *rex.input == NUL && rex.lnum <= rex.reg_maxline) { reg_nextline(); } @@ -4732,7 +4721,6 @@ regmatch( regtry( bt_regprog_T *prog, colnr_T col, - proftime_T *tm, // timeout limit or NULL int *timed_out) // flag set on timeout or NULL { rex.input = rex.line + col; @@ -4742,7 +4730,7 @@ regtry( rex.need_clear_zsubexpr = (prog->reghasz == REX_SET); #endif - if (regmatch(prog->program + 1, tm, timed_out) == 0) + if (regmatch(prog->program + 1, timed_out) == 0) return 0; cleanup_subexpr(); @@ -4817,7 +4805,6 @@ regtry( bt_regexec_both( char_u *line, colnr_T col, // column to start looking for match - proftime_T *tm, // timeout limit or NULL int *timed_out) // flag set on timeout or NULL { bt_regprog_T *prog; @@ -4940,15 +4927,12 @@ bt_regexec_both( && (((enc_utf8 && utf_fold(prog->regstart) == utf_fold(c))) || (c < 255 && prog->regstart < 255 && MB_TOLOWER(prog->regstart) == MB_TOLOWER(c))))) - retval = regtry(prog, col, tm, timed_out); + retval = regtry(prog, col, timed_out); else retval = 0; } else { -#ifdef FEAT_RELTIME - int tm_count = 0; -#endif // Messy cases: unanchored match. while (!got_int) { @@ -4975,7 +4959,7 @@ bt_regexec_both( break; } - retval = regtry(prog, col, tm, timed_out); + retval = regtry(prog, col, timed_out); if (retval > 0) break; @@ -4992,18 +4976,11 @@ bt_regexec_both( else ++col; #ifdef FEAT_RELTIME - // Check for timeout once in 500 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 (tm != NULL && ++tm_count == 500) + if (*timeout_flag) { - tm_count = 0; - if (profile_passed_limit(tm)) - { - if (timed_out != NULL) - *timed_out = TRUE; - break; - } + if (timed_out != NULL) + *timed_out = TRUE; + break; } #endif } @@ -5067,7 +5044,7 @@ bt_regexec_nl( rex.reg_icombine = FALSE; rex.reg_maxcol = 0; - return bt_regexec_both(line, col, NULL, NULL); + return bt_regexec_both(line, col, NULL); } /* @@ -5085,11 +5062,10 @@ bt_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 set on timeout or NULL { init_regexec_multi(rmp, win, buf, lnum); - return bt_regexec_both(NULL, col, tm, timed_out); + return bt_regexec_both(NULL, col, timed_out); } /* |