comparison src/regexp_nfa.c @ 4742:6a706ca7a889 v7.3.1118

updated for version 7.3.1118 Problem: Match failure rate is not very specific. Solution: Tune the failure rate for match items.
author Bram Moolenaar <bram@vim.org>
date Wed, 05 Jun 2013 11:46:25 +0200
parents 97560c16ca99
children a62695305e03
comparison
equal deleted inserted replaced
4741:72ab0f628a55 4742:6a706ca7a889
3954 3954
3955 /* detect looping */ 3955 /* detect looping */
3956 if (depth > 4) 3956 if (depth > 4)
3957 return 1; 3957 return 1;
3958 3958
3959 if (c == NFA_SPLIT) 3959 switch (c)
3960 { 3960 {
3961 if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT) 3961 case NFA_SPLIT:
3962 if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT)
3963 /* avoid recursive stuff */
3964 return 1;
3965 /* two alternatives, use the lowest failure chance */
3966 l = failure_chance(state->out, depth + 1);
3967 r = failure_chance(state->out1, depth + 1);
3968 return l < r ? l : r;
3969
3970 case NFA_ANY:
3971 /* matches anything, unlikely to fail */
3962 return 1; 3972 return 1;
3963 l = failure_chance(state->out, depth + 1); 3973 case NFA_MATCH:
3964 r = failure_chance(state->out1, depth + 1); 3974 /* empty match works always */
3965 return l < r ? l : r; 3975 return 0;
3966 } 3976
3967 if (c == NFA_ANY) 3977 case NFA_BOL:
3968 return 1; 3978 case NFA_EOL:
3969 if (c > 0) 3979 case NFA_BOF:
3970 return 99; 3980 case NFA_EOF:
3971 if ((c >= NFA_MOPEN && c <= NFA_MOPEN9) 3981 case NFA_NEWL:
3982 return 99;
3983
3984 case NFA_BOW:
3985 case NFA_EOW:
3986 return 90;
3987
3988 case NFA_MOPEN:
3989 case NFA_MOPEN1:
3990 case NFA_MOPEN2:
3991 case NFA_MOPEN3:
3992 case NFA_MOPEN4:
3993 case NFA_MOPEN5:
3994 case NFA_MOPEN6:
3995 case NFA_MOPEN7:
3996 case NFA_MOPEN8:
3997 case NFA_MOPEN9:
3972 #ifdef FEAT_SYN_HL 3998 #ifdef FEAT_SYN_HL
3973 || (c >= NFA_ZOPEN && c <= NFA_ZOPEN9) 3999 case NFA_ZOPEN:
3974 #endif 4000 case NFA_ZOPEN1:
3975 || c == NFA_NOPEN) 4001 case NFA_ZOPEN2:
3976 return failure_chance(state->out, depth + 1); 4002 case NFA_ZOPEN3:
3977 /* something else */ 4003 case NFA_ZOPEN4:
4004 case NFA_ZOPEN5:
4005 case NFA_ZOPEN6:
4006 case NFA_ZOPEN7:
4007 case NFA_ZOPEN8:
4008 case NFA_ZOPEN9:
4009 case NFA_ZCLOSE:
4010 case NFA_ZCLOSE1:
4011 case NFA_ZCLOSE2:
4012 case NFA_ZCLOSE3:
4013 case NFA_ZCLOSE4:
4014 case NFA_ZCLOSE5:
4015 case NFA_ZCLOSE6:
4016 case NFA_ZCLOSE7:
4017 case NFA_ZCLOSE8:
4018 case NFA_ZCLOSE9:
4019 #endif
4020 case NFA_NOPEN:
4021 case NFA_MCLOSE:
4022 case NFA_MCLOSE1:
4023 case NFA_MCLOSE2:
4024 case NFA_MCLOSE3:
4025 case NFA_MCLOSE4:
4026 case NFA_MCLOSE5:
4027 case NFA_MCLOSE6:
4028 case NFA_MCLOSE7:
4029 case NFA_MCLOSE8:
4030 case NFA_MCLOSE9:
4031 case NFA_NCLOSE:
4032 return failure_chance(state->out, depth + 1);
4033
4034 case NFA_BACKREF1:
4035 case NFA_BACKREF2:
4036 case NFA_BACKREF3:
4037 case NFA_BACKREF4:
4038 case NFA_BACKREF5:
4039 case NFA_BACKREF6:
4040 case NFA_BACKREF7:
4041 case NFA_BACKREF8:
4042 case NFA_BACKREF9:
4043 #ifdef FEAT_SYN_HL
4044 case NFA_ZREF1:
4045 case NFA_ZREF2:
4046 case NFA_ZREF3:
4047 case NFA_ZREF4:
4048 case NFA_ZREF5:
4049 case NFA_ZREF6:
4050 case NFA_ZREF7:
4051 case NFA_ZREF8:
4052 case NFA_ZREF9:
4053 #endif
4054 /* backreferences don't match in many places */
4055 return 94;
4056
4057 case NFA_LNUM_GT:
4058 case NFA_LNUM_LT:
4059 case NFA_COL_GT:
4060 case NFA_COL_LT:
4061 case NFA_VCOL_GT:
4062 case NFA_VCOL_LT:
4063 case NFA_MARK_GT:
4064 case NFA_MARK_LT:
4065 #ifdef FEAT_VISUAL
4066 case NFA_VISUAL:
4067 #endif
4068 /* before/after positions don't match very often */
4069 return 85;
4070
4071 case NFA_LNUM:
4072 return 90;
4073
4074 case NFA_CURSOR:
4075 case NFA_COL:
4076 case NFA_VCOL:
4077 case NFA_MARK:
4078 /* specific positions rarely match */
4079 return 98;
4080
4081 case NFA_COMPOSING:
4082 return 95;
4083
4084 default:
4085 if (c > 0)
4086 /* character match fails often */
4087 return 95;
4088 }
4089
4090 /* something else, includes character classes */
3978 return 50; 4091 return 50;
3979 } 4092 }
3980 4093
3981 /* 4094 /*
3982 * Main matching routine. 4095 * Main matching routine.