0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

updated for version 7.3.1118

Problem:    Match failure rate is not very specific.
Solution:   Tune the failure rate for match items.
This commit is contained in:
Bram Moolenaar
2013-06-05 11:46:25 +02:00
parent d75799ab7f
commit e2b8cb3b15
2 changed files with 130 additions and 15 deletions

View File

@@ -3956,25 +3956,138 @@ failure_chance(state, depth)
if (depth > 4) if (depth > 4)
return 1; return 1;
if (c == NFA_SPLIT) switch (c)
{ {
if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT) case NFA_SPLIT:
if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT)
/* avoid recursive stuff */
return 1;
/* two alternatives, use the lowest failure chance */
l = failure_chance(state->out, depth + 1);
r = failure_chance(state->out1, depth + 1);
return l < r ? l : r;
case NFA_ANY:
/* matches anything, unlikely to fail */
return 1; return 1;
l = failure_chance(state->out, depth + 1); case NFA_MATCH:
r = failure_chance(state->out1, depth + 1); /* empty match works always */
return l < r ? l : r; return 0;
}
if (c == NFA_ANY) case NFA_BOL:
return 1; case NFA_EOL:
if (c > 0) case NFA_BOF:
return 99; case NFA_EOF:
if ((c >= NFA_MOPEN && c <= NFA_MOPEN9) case NFA_NEWL:
return 99;
case NFA_BOW:
case NFA_EOW:
return 90;
case NFA_MOPEN:
case NFA_MOPEN1:
case NFA_MOPEN2:
case NFA_MOPEN3:
case NFA_MOPEN4:
case NFA_MOPEN5:
case NFA_MOPEN6:
case NFA_MOPEN7:
case NFA_MOPEN8:
case NFA_MOPEN9:
#ifdef FEAT_SYN_HL #ifdef FEAT_SYN_HL
|| (c >= NFA_ZOPEN && c <= NFA_ZOPEN9) case NFA_ZOPEN:
case NFA_ZOPEN1:
case NFA_ZOPEN2:
case NFA_ZOPEN3:
case NFA_ZOPEN4:
case NFA_ZOPEN5:
case NFA_ZOPEN6:
case NFA_ZOPEN7:
case NFA_ZOPEN8:
case NFA_ZOPEN9:
case NFA_ZCLOSE:
case NFA_ZCLOSE1:
case NFA_ZCLOSE2:
case NFA_ZCLOSE3:
case NFA_ZCLOSE4:
case NFA_ZCLOSE5:
case NFA_ZCLOSE6:
case NFA_ZCLOSE7:
case NFA_ZCLOSE8:
case NFA_ZCLOSE9:
#endif #endif
|| c == NFA_NOPEN) case NFA_NOPEN:
return failure_chance(state->out, depth + 1); case NFA_MCLOSE:
/* something else */ case NFA_MCLOSE1:
case NFA_MCLOSE2:
case NFA_MCLOSE3:
case NFA_MCLOSE4:
case NFA_MCLOSE5:
case NFA_MCLOSE6:
case NFA_MCLOSE7:
case NFA_MCLOSE8:
case NFA_MCLOSE9:
case NFA_NCLOSE:
return failure_chance(state->out, depth + 1);
case NFA_BACKREF1:
case NFA_BACKREF2:
case NFA_BACKREF3:
case NFA_BACKREF4:
case NFA_BACKREF5:
case NFA_BACKREF6:
case NFA_BACKREF7:
case NFA_BACKREF8:
case NFA_BACKREF9:
#ifdef FEAT_SYN_HL
case NFA_ZREF1:
case NFA_ZREF2:
case NFA_ZREF3:
case NFA_ZREF4:
case NFA_ZREF5:
case NFA_ZREF6:
case NFA_ZREF7:
case NFA_ZREF8:
case NFA_ZREF9:
#endif
/* backreferences don't match in many places */
return 94;
case NFA_LNUM_GT:
case NFA_LNUM_LT:
case NFA_COL_GT:
case NFA_COL_LT:
case NFA_VCOL_GT:
case NFA_VCOL_LT:
case NFA_MARK_GT:
case NFA_MARK_LT:
#ifdef FEAT_VISUAL
case NFA_VISUAL:
#endif
/* before/after positions don't match very often */
return 85;
case NFA_LNUM:
return 90;
case NFA_CURSOR:
case NFA_COL:
case NFA_VCOL:
case NFA_MARK:
/* specific positions rarely match */
return 98;
case NFA_COMPOSING:
return 95;
default:
if (c > 0)
/* character match fails often */
return 95;
}
/* something else, includes character classes */
return 50; return 50;
} }

View File

@@ -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 */
/**/
1118,
/**/ /**/
1117, 1117,
/**/ /**/