To: vim_dev@googlegroups.com Subject: Patch 7.4.613 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.613 Problem: The NFA engine does not implement the 'redrawtime' time limit. Solution: Implement the time limit. Files: src/regexp_nfa.c *** ../vim-7.4.612/src/regexp_nfa.c 2015-01-27 14:54:07.944583588 +0100 --- src/regexp_nfa.c 2015-02-03 16:25:58.681726505 +0100 *************** *** 311,318 **** static void nfa_save_listids __ARGS((nfa_regprog_T *prog, int *list)); static void nfa_restore_listids __ARGS((nfa_regprog_T *prog, int *list)); static int nfa_re_num_cmp __ARGS((long_u val, int op, long_u pos)); ! static long nfa_regtry __ARGS((nfa_regprog_T *prog, colnr_T col)); ! static long nfa_regexec_both __ARGS((char_u *line, colnr_T col)); static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags)); static void nfa_regfree __ARGS((regprog_T *prog)); static int nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr)); --- 311,318 ---- static void nfa_save_listids __ARGS((nfa_regprog_T *prog, int *list)); static void nfa_restore_listids __ARGS((nfa_regprog_T *prog, int *list)); static int nfa_re_num_cmp __ARGS((long_u val, int op, long_u pos)); ! static long nfa_regtry __ARGS((nfa_regprog_T *prog, colnr_T col, proftime_T *tm)); ! static long nfa_regexec_both __ARGS((char_u *line, colnr_T col, proftime_T *tm)); static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags)); static void nfa_regfree __ARGS((regprog_T *prog)); static int nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr)); *************** *** 3850,3855 **** --- 3850,3859 ---- /* Used during execution: whether a match has been found. */ static int nfa_match; + #ifdef FEAT_RELTIME + static proftime_T *nfa_time_limit; + static int nfa_time_count; + #endif static void copy_pim __ARGS((nfa_pim_T *to, nfa_pim_T *from)); static void clear_sub __ARGS((regsub_T *sub)); *************** *** 5449,5454 **** --- 5453,5462 ---- fast_breakcheck(); if (got_int) return FALSE; + #ifdef FEAT_RELTIME + if (nfa_time_limit != NULL && profile_passed_limit(nfa_time_limit)) + return FALSE; + #endif nfa_match = FALSE; *************** *** 6789,6797 **** break; /* Allow interrupting with CTRL-C. */ ! fast_breakcheck(); if (got_int) break; } #ifdef ENABLE_LOG --- 6797,6814 ---- break; /* Allow interrupting with CTRL-C. */ ! line_breakcheck(); if (got_int) break; + #ifdef FEAT_RELTIME + /* Check for timeout once in a twenty times to avoid overhead. */ + if (nfa_time_limit != NULL && ++nfa_time_count == 20) + { + nfa_time_count = 0; + if (profile_passed_limit(nfa_time_limit)) + break; + } + #endif } #ifdef ENABLE_LOG *************** *** 6818,6826 **** * Returns <= 0 for failure, number of lines contained in the match otherwise. */ static long ! nfa_regtry(prog, col) nfa_regprog_T *prog; colnr_T col; { int i; regsubs_T subs, m; --- 6835,6844 ---- * Returns <= 0 for failure, number of lines contained in the match otherwise. */ static long ! nfa_regtry(prog, col, tm) nfa_regprog_T *prog; colnr_T col; + proftime_T *tm; /* timeout limit or NULL */ { int i; regsubs_T subs, m; *************** *** 6831,6836 **** --- 6849,6858 ---- #endif reginput = regline + col; + #ifdef FEAT_RELTIME + nfa_time_limit = tm; + nfa_time_count = 0; + #endif #ifdef ENABLE_LOG f = fopen(NFA_REGEXP_RUN_LOG, "a"); *************** *** 6951,6959 **** * Returns <= 0 for failure, number of lines contained in the match otherwise. */ static long ! nfa_regexec_both(line, startcol) char_u *line; colnr_T startcol; /* column to start looking for match */ { nfa_regprog_T *prog; long retval = 0L; --- 6973,6982 ---- * Returns <= 0 for failure, number of lines contained in the match otherwise. */ static long ! nfa_regexec_both(line, startcol, tm) char_u *line; colnr_T startcol; /* column to start looking for match */ + proftime_T *tm; /* timeout limit or NULL */ { nfa_regprog_T *prog; long retval = 0L; *************** *** 7047,7053 **** prog->state[i].lastlist[1] = 0; } ! retval = nfa_regtry(prog, col); nfa_regengine.expr = NULL; --- 7070,7076 ---- prog->state[i].lastlist[1] = 0; } ! retval = nfa_regtry(prog, col, tm); nfa_regengine.expr = NULL; *************** *** 7209,7215 **** ireg_icombine = FALSE; #endif ireg_maxcol = 0; ! return nfa_regexec_both(line, col); } --- 7232,7238 ---- ireg_icombine = FALSE; #endif ireg_maxcol = 0; ! return nfa_regexec_both(line, col, NULL); } *************** *** 7245,7251 **** 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 UNUSED; /* timeout limit or NULL */ { reg_match = NULL; reg_mmatch = rmp; --- 7268,7274 ---- 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 */ { reg_match = NULL; reg_mmatch = rmp; *************** *** 7260,7266 **** #endif ireg_maxcol = rmp->rmm_maxcol; ! return nfa_regexec_both(NULL, col); } #ifdef DEBUG --- 7283,7289 ---- #endif ireg_maxcol = rmp->rmm_maxcol; ! return nfa_regexec_both(NULL, col, tm); } #ifdef DEBUG *** ../vim-7.4.612/src/version.c 2015-02-03 16:07:44.193584399 +0100 --- src/version.c 2015-02-03 16:48:54.770821421 +0100 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 613, /**/ -- In Joseph Heller's novel "Catch-22", the main character tries to get out of a war by proving he is crazy. But the mere fact he wants to get out of the war only shows he isn't crazy -- creating the original "Catch-22". /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///