mirror of
https://github.com/vim/vim.git
synced 2025-08-23 19:34:27 -04:00
updated for version 7.3.1103
Problem: New regexp engine: overhead in saving and restoring. Solution: Make saving and restoring list IDs faster. Don't copy or check \z subexpressions when they are not used.
This commit is contained in:
parent
9f5d600723
commit
f6de032afe
147
src/regexp_nfa.c
147
src/regexp_nfa.c
@ -237,6 +237,9 @@ static int nfa_has_zend;
|
|||||||
/* NFA regexp \1 .. \9 encountered. */
|
/* NFA regexp \1 .. \9 encountered. */
|
||||||
static int nfa_has_backref;
|
static int nfa_has_backref;
|
||||||
|
|
||||||
|
/* NFA regexp has \z( ), set zsubexpr. */
|
||||||
|
static int nfa_has_zsubexpr;
|
||||||
|
|
||||||
/* Number of sub expressions actually being used during execution. 1 if only
|
/* Number of sub expressions actually being used during execution. 1 if only
|
||||||
* the whole match (subexpr 0) is used. */
|
* the whole match (subexpr 0) is used. */
|
||||||
static int nfa_nsubexpr;
|
static int nfa_nsubexpr;
|
||||||
@ -272,10 +275,8 @@ static nfa_state_T *alloc_state __ARGS((int c, nfa_state_T *out, nfa_state_T *ou
|
|||||||
static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size));
|
static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size));
|
||||||
static int check_char_class __ARGS((int class, int c));
|
static int check_char_class __ARGS((int class, int c));
|
||||||
static void st_error __ARGS((int *postfix, int *end, int *p));
|
static void st_error __ARGS((int *postfix, int *end, int *p));
|
||||||
static void nfa_set_neg_listids __ARGS((nfa_state_T *start));
|
static void nfa_save_listids __ARGS((nfa_regprog_T *prog, int *list));
|
||||||
static void nfa_set_null_listids __ARGS((nfa_state_T *start));
|
static void nfa_restore_listids __ARGS((nfa_regprog_T *prog, int *list));
|
||||||
static void nfa_save_listids __ARGS((nfa_state_T *start, int *list));
|
|
||||||
static void nfa_restore_listids __ARGS((nfa_state_T *start, int *list));
|
|
||||||
static int nfa_re_num_cmp __ARGS((long_u val, int op, long_u pos));
|
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_regtry __ARGS((nfa_regprog_T *prog, colnr_T col));
|
||||||
static long nfa_regexec_both __ARGS((char_u *line, colnr_T col));
|
static long nfa_regexec_both __ARGS((char_u *line, colnr_T col));
|
||||||
@ -3000,6 +3001,24 @@ sub_equal(sub1, sub2)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_LOG
|
||||||
|
static void
|
||||||
|
report_state(char *action, regsub_T *sub, nfa_state_T *state, int lid);
|
||||||
|
{
|
||||||
|
int col;
|
||||||
|
|
||||||
|
if (sub->in_use <= 0)
|
||||||
|
col = -1;
|
||||||
|
else if (REG_MULTI)
|
||||||
|
col = sub->list.multi[0].start.col;
|
||||||
|
else
|
||||||
|
col = (int)(sub->list.line[0].start - regline);
|
||||||
|
nfa_set_code(state->c);
|
||||||
|
fprintf(log_fd, "> %s state %d to list %d. char %d: %s (start col %d)\n",
|
||||||
|
action, abs(state->id), lid, state->c, code, col);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addstate(l, state, subs, off)
|
addstate(l, state, subs, off)
|
||||||
nfa_list_T *l; /* runtime state list */
|
nfa_list_T *l; /* runtime state list */
|
||||||
@ -3118,7 +3137,8 @@ skip_add:
|
|||||||
if (thread->state->id == state->id
|
if (thread->state->id == state->id
|
||||||
&& sub_equal(&thread->subs.norm, &subs->norm)
|
&& sub_equal(&thread->subs.norm, &subs->norm)
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
&& sub_equal(&thread->subs.synt, &subs->synt)
|
&& (!nfa_has_zsubexpr ||
|
||||||
|
sub_equal(&thread->subs.synt, &subs->synt))
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
goto skip_add;
|
goto skip_add;
|
||||||
@ -3141,41 +3161,18 @@ skip_add:
|
|||||||
thread->state = state;
|
thread->state = state;
|
||||||
copy_sub(&thread->subs.norm, &subs->norm);
|
copy_sub(&thread->subs.norm, &subs->norm);
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
|
if (nfa_has_zsubexpr)
|
||||||
copy_sub(&thread->subs.synt, &subs->synt);
|
copy_sub(&thread->subs.synt, &subs->synt);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_LOG
|
#ifdef ENABLE_LOG
|
||||||
{
|
report_state("Adding", &thread->subs.norm, state, l->id);
|
||||||
int col;
|
|
||||||
|
|
||||||
if (thread->subs.norm.in_use <= 0)
|
|
||||||
col = -1;
|
|
||||||
else if (REG_MULTI)
|
|
||||||
col = thread->subs.norm.list.multi[0].start.col;
|
|
||||||
else
|
|
||||||
col = (int)(thread->subs.norm.list.line[0].start - regline);
|
|
||||||
nfa_set_code(state->c);
|
|
||||||
fprintf(log_fd, "> Adding state %d to list %d. char %d: %s (start col %d)\n",
|
|
||||||
abs(state->id), l->id, state->c, code, col);
|
|
||||||
did_print = TRUE;
|
did_print = TRUE;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_LOG
|
#ifdef ENABLE_LOG
|
||||||
if (!did_print)
|
if (!did_print)
|
||||||
{
|
report_state("Processing", &subs->norm, state, l->id);
|
||||||
int col;
|
|
||||||
|
|
||||||
if (subs->norm.in_use <= 0)
|
|
||||||
col = -1;
|
|
||||||
else if (REG_MULTI)
|
|
||||||
col = subs->norm.list.multi[0].start.col;
|
|
||||||
else
|
|
||||||
col = (int)(subs->norm.list.line[0].start - regline);
|
|
||||||
nfa_set_code(state->c);
|
|
||||||
fprintf(log_fd, "> Processing state %d for list %d. char %d: %s (start col %d)\n",
|
|
||||||
abs(state->id), l->id, state->c, code, col);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
switch (state->c)
|
switch (state->c)
|
||||||
{
|
{
|
||||||
@ -3600,49 +3597,24 @@ match_zref(subidx, bytelen)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set all NFA nodes' list ID equal to -1.
|
* Save list IDs for all NFA states of "prog" into "list".
|
||||||
|
* Also reset the IDs to zero.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
nfa_set_neg_listids(start)
|
nfa_save_listids(prog, list)
|
||||||
nfa_state_T *start;
|
nfa_regprog_T *prog;
|
||||||
{
|
|
||||||
if (start != NULL && start->lastlist >= 0)
|
|
||||||
{
|
|
||||||
start->lastlist = -1;
|
|
||||||
nfa_set_neg_listids(start->out);
|
|
||||||
nfa_set_neg_listids(start->out1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set all NFA nodes' list ID equal to 0.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
nfa_set_null_listids(start)
|
|
||||||
nfa_state_T *start;
|
|
||||||
{
|
|
||||||
if (start != NULL && start->lastlist == -1)
|
|
||||||
{
|
|
||||||
start->lastlist = 0;
|
|
||||||
nfa_set_null_listids(start->out);
|
|
||||||
nfa_set_null_listids(start->out1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Save list IDs for all NFA states in "list".
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
nfa_save_listids(start, list)
|
|
||||||
nfa_state_T *start;
|
|
||||||
int *list;
|
int *list;
|
||||||
{
|
{
|
||||||
if (start != NULL && start->lastlist != -1)
|
int i;
|
||||||
|
nfa_state_T *p;
|
||||||
|
|
||||||
|
/* Order in the list is reverse, it's a bit faster that way. */
|
||||||
|
p = &prog->state[0];
|
||||||
|
for (i = prog->nstate; --i >= 0; )
|
||||||
{
|
{
|
||||||
list[abs(start->id)] = start->lastlist;
|
list[i] = p->lastlist;
|
||||||
start->lastlist = -1;
|
p->lastlist = 0;
|
||||||
nfa_save_listids(start->out, list);
|
++p;
|
||||||
nfa_save_listids(start->out1, list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3650,15 +3622,18 @@ nfa_save_listids(start, list)
|
|||||||
* Restore list IDs from "list" to all NFA states.
|
* Restore list IDs from "list" to all NFA states.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
nfa_restore_listids(start, list)
|
nfa_restore_listids(prog, list)
|
||||||
nfa_state_T *start;
|
nfa_regprog_T *prog;
|
||||||
int *list;
|
int *list;
|
||||||
{
|
{
|
||||||
if (start != NULL && start->lastlist == -1)
|
int i;
|
||||||
|
nfa_state_T *p;
|
||||||
|
|
||||||
|
p = &prog->state[0];
|
||||||
|
for (i = prog->nstate; --i >= 0; )
|
||||||
{
|
{
|
||||||
start->lastlist = list[abs(start->id)];
|
p->lastlist = list[i];
|
||||||
nfa_restore_listids(start->out, list);
|
++p;
|
||||||
nfa_restore_listids(start->out1, list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3673,7 +3648,7 @@ nfa_re_num_cmp(val, op, pos)
|
|||||||
return val == pos;
|
return val == pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nfa_regmatch __ARGS((nfa_state_T *start, regsubs_T *submatch, regsubs_T *m));
|
static int nfa_regmatch __ARGS((nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *submatch, regsubs_T *m));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main matching routine.
|
* Main matching routine.
|
||||||
@ -3686,7 +3661,8 @@ static int nfa_regmatch __ARGS((nfa_state_T *start, regsubs_T *submatch, regsubs
|
|||||||
* Note: Caller must ensure that: start != NULL.
|
* Note: Caller must ensure that: start != NULL.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
nfa_regmatch(start, submatch, m)
|
nfa_regmatch(prog, start, submatch, m)
|
||||||
|
nfa_regprog_T *prog;
|
||||||
nfa_state_T *start;
|
nfa_state_T *start;
|
||||||
regsubs_T *submatch;
|
regsubs_T *submatch;
|
||||||
regsubs_T *m;
|
regsubs_T *m;
|
||||||
@ -3872,6 +3848,7 @@ nfa_regmatch(start, submatch, m)
|
|||||||
nfa_match = TRUE;
|
nfa_match = TRUE;
|
||||||
copy_sub(&submatch->norm, &t->subs.norm);
|
copy_sub(&submatch->norm, &t->subs.norm);
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
|
if (nfa_has_zsubexpr)
|
||||||
copy_sub(&submatch->synt, &t->subs.synt);
|
copy_sub(&submatch->synt, &t->subs.synt);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_LOG
|
#ifdef ENABLE_LOG
|
||||||
@ -3928,6 +3905,7 @@ nfa_regmatch(start, submatch, m)
|
|||||||
{
|
{
|
||||||
copy_sub(&m->norm, &t->subs.norm);
|
copy_sub(&m->norm, &t->subs.norm);
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
|
if (nfa_has_zsubexpr)
|
||||||
copy_sub(&m->synt, &t->subs.synt);
|
copy_sub(&m->synt, &t->subs.synt);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -4024,12 +4002,10 @@ nfa_regmatch(start, submatch, m)
|
|||||||
/* Have to clear the listid field of the NFA nodes, so that
|
/* Have to clear the listid field of the NFA nodes, so that
|
||||||
* nfa_regmatch() and addstate() can run properly after
|
* nfa_regmatch() and addstate() can run properly after
|
||||||
* recursion. */
|
* recursion. */
|
||||||
nfa_save_listids(start, listids);
|
nfa_save_listids(prog, listids);
|
||||||
nfa_set_null_listids(start);
|
|
||||||
nfa_endp = endposp;
|
nfa_endp = endposp;
|
||||||
result = nfa_regmatch(t->state->out, submatch, m);
|
result = nfa_regmatch(prog, t->state->out, submatch, m);
|
||||||
nfa_set_neg_listids(start);
|
nfa_restore_listids(prog, listids);
|
||||||
nfa_restore_listids(start, listids);
|
|
||||||
|
|
||||||
/* restore position in input text */
|
/* restore position in input text */
|
||||||
reginput = save_reginput;
|
reginput = save_reginput;
|
||||||
@ -4665,7 +4641,12 @@ nfa_regtry(prog, col)
|
|||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
/* Clear the external match subpointers if necessary. */
|
/* Clear the external match subpointers if necessary. */
|
||||||
if (prog->reghasz == REX_SET)
|
if (prog->reghasz == REX_SET)
|
||||||
|
{
|
||||||
|
nfa_has_zsubexpr = TRUE;
|
||||||
need_clear_zsubexpr = TRUE;
|
need_clear_zsubexpr = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
nfa_has_zsubexpr = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_LOG
|
#ifdef ENABLE_LOG
|
||||||
@ -4694,7 +4675,7 @@ nfa_regtry(prog, col)
|
|||||||
clear_sub(&m.synt);
|
clear_sub(&m.synt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (nfa_regmatch(start, &subs, &m) == FALSE)
|
if (nfa_regmatch(prog, start, &subs, &m) == FALSE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cleanup_subexpr();
|
cleanup_subexpr();
|
||||||
|
@ -728,6 +728,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1103,
|
||||||
/**/
|
/**/
|
||||||
1102,
|
1102,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user