Mercurial > vim
diff src/regexp.c @ 4744:a62695305e03 v7.3.1119
updated for version 7.3.1119
Problem: Flags in 'cpo' are search for several times.
Solution: Store the result and re-use the flags.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 05 Jun 2013 12:43:09 +0200 |
parents | 0798b096bab3 |
children | d1376091d18b |
line wrap: on
line diff
--- a/src/regexp.c +++ b/src/regexp.c @@ -365,6 +365,7 @@ static char_u e_unmatchedpar[] = N_("E55 static char_u e_z_not_allowed[] = N_("E66: \\z( not allowed here"); static char_u e_z1_not_allowed[] = N_("E67: \\z1 et al. not allowed here"); #endif +static char_u e_missing_sb[] = N_("E69: Missing ] after %s%%["); #define NOT_MULTI 0 #define MULTI_ONE 1 @@ -1173,6 +1174,16 @@ get_coll_element(pp) return 0; } +static void get_cpo_flags __ARGS((void)); +static int reg_cpo_lit; /* 'cpoptions' contains 'l' flag */ +static int reg_cpo_bsl; /* 'cpoptions' contains '\' flag */ + + static void +get_cpo_flags() +{ + reg_cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL; + reg_cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL; +} /* * Skip over a "[]" range. @@ -1183,15 +1194,10 @@ get_coll_element(pp) skip_anyof(p) char_u *p; { - int cpo_lit; /* 'cpoptions' contains 'l' flag */ - int cpo_bsl; /* 'cpoptions' contains '\' flag */ #ifdef FEAT_MBYTE int l; #endif - cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL; - cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL; - if (*p == '^') /* Complement of range. */ ++p; if (*p == ']' || *p == '-') @@ -1210,9 +1216,9 @@ skip_anyof(p) mb_ptr_adv(p); } else if (*p == '\\' - && !cpo_bsl + && !reg_cpo_bsl && (vim_strchr(REGEXP_INRANGE, p[1]) != NULL - || (!cpo_lit && vim_strchr(REGEXP_ABBR, p[1]) != NULL))) + || (!reg_cpo_lit && vim_strchr(REGEXP_ABBR, p[1]) != NULL))) p += 2; else if (*p == '[') { @@ -1251,6 +1257,7 @@ skip_regexp(startp, dirc, magic, newp) mymagic = MAGIC_ON; else mymagic = MAGIC_OFF; + get_cpo_flags(); for (; p[0] != NUL; mb_ptr_adv(p)) { @@ -1462,6 +1469,7 @@ regcomp_start(expr, re_flags) reg_magic = MAGIC_OFF; reg_string = (re_flags & RE_STRING); reg_strict = (re_flags & RE_STRICT); + get_cpo_flags(); num_complex_braces = 0; regnpar = 1; @@ -1909,15 +1917,11 @@ regatom(flagp) { char_u *ret; int flags; - int cpo_lit; /* 'cpoptions' contains 'l' flag */ - int cpo_bsl; /* 'cpoptions' contains '\' flag */ int c; char_u *p; int extra = 0; *flagp = WORST; /* Tentatively. */ - cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL; - cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL; c = getchr(); switch (c) @@ -2207,7 +2211,7 @@ regatom(flagp) while ((c = getchr()) != ']') { if (c == NUL) - EMSG2_RET_NULL(_("E69: Missing ] after %s%%["), + EMSG2_RET_NULL(_(e_missing_sb), reg_magic == MAGIC_ALL); br = regnode(BRANCH); if (ret == NULL) @@ -2410,7 +2414,7 @@ collection: } /* Handle \o40, \x20 and \u20AC style sequences */ - if (endc == '\\' && !cpo_lit && !cpo_bsl) + if (endc == '\\' && !reg_cpo_lit && !reg_cpo_bsl) endc = coll_get_char(); if (startc > endc) @@ -2452,9 +2456,9 @@ collection: * Posix doesn't recognize backslash at all. */ else if (*regparse == '\\' - && !cpo_bsl + && !reg_cpo_bsl && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL - || (!cpo_lit + || (!reg_cpo_lit && vim_strchr(REGEXP_ABBR, regparse[1]) != NULL))) {