updated for version 7.0047
diff --git a/src/fileio.c b/src/fileio.c
index c888f35..ee1c90b 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6585,7 +6585,7 @@
char_u *pat; /* pattern as typed (NULL when pattern
has been removed) */
int patlen; /* strlen() of pat */
- char_u *reg_pat; /* pattern converted to regexp */
+ regprog_T *reg_prog; /* compiled regprog for pattern */
char allow_dirs; /* Pattern may match whole path */
char last; /* last pattern for apply_autocmds() */
AutoCmd *cmds; /* list of commands to do */
@@ -6865,7 +6865,7 @@
if (ap->pat == NULL)
{
*prev_ap = ap->next;
- vim_free(ap->reg_pat);
+ vim_free(ap->reg_prog);
vim_free(ap);
}
else
@@ -7167,8 +7167,6 @@
if (old_ei != NULL)
{
set_string_option_direct((char_u *)"ei", -1, old_ei, OPT_FREE);
- apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
- curbuf->b_fname, TRUE, curbuf);
vim_free(old_ei);
}
}
@@ -7542,15 +7540,20 @@
if (is_buflocal)
{
ap->buflocal_nr = buflocal_nr;
- ap->reg_pat = NULL;
+ ap->reg_prog = NULL;
}
else
{
+ char_u *reg_pat;
+
ap->buflocal_nr = 0;
- ap->reg_pat = file_pat_to_reg_pat(pat, endpat,
+ reg_pat = file_pat_to_reg_pat(pat, endpat,
&ap->allow_dirs, TRUE);
- if (ap->reg_pat == NULL)
+ if (reg_pat != NULL)
+ ap->reg_prog = vim_regcomp(reg_pat, RE_MAGIC);
+ if (reg_pat == NULL || ap->reg_prog == NULL)
{
+ vim_free(reg_pat);
vim_free(ap->pat);
vim_free(ap);
return FAIL;
@@ -8250,8 +8253,8 @@
{
/* execution-condition */
if (ap->buflocal_nr == 0
- ? (match_file_pat(ap->reg_pat, apc->fname, apc->sfname,
- apc->tail, ap->allow_dirs))
+ ? (match_file_pat(NULL, ap->reg_prog, apc->fname,
+ apc->sfname, apc->tail, ap->allow_dirs))
: ap->buflocal_nr == apc->arg_bufnr)
{
name = event_nr2name(apc->event);
@@ -8381,8 +8384,8 @@
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
if (ap->pat != NULL && ap->cmds != NULL
&& (ap->buflocal_nr == 0
- ? match_file_pat(ap->reg_pat, fname, sfname, tail,
- ap->allow_dirs)
+ ? match_file_pat(NULL, ap->reg_prog,
+ fname, sfname, tail, ap->allow_dirs)
: buf != NULL && ap->buflocal_nr == buf->b_fnum
))
{
@@ -8549,13 +8552,16 @@
#if defined(FEAT_AUTOCMD) || defined(FEAT_WILDIGN) || defined(PROTO)
/*
- * Try matching a filename with a pattern.
+ * Try matching a filename with a "pattern" ("prog" is NULL), or use the
+ * precompiled regprog "prog" ("pattern" is NULL). That avoids calling
+ * vim_regcomp() often.
* Used for autocommands and 'wildignore'.
* Returns TRUE if there is a match, FALSE otherwise.
*/
int
-match_file_pat(pattern, fname, sfname, tail, allow_dirs)
+match_file_pat(pattern, prog, fname, sfname, tail, allow_dirs)
char_u *pattern; /* pattern to match with */
+ regprog_T *prog; /* pre-compiled regprog or NULL */
char_u *fname; /* full path of file name */
char_u *sfname; /* short file name or NULL */
char_u *tail; /* tail of path */
@@ -8610,7 +8616,12 @@
}
else
#endif
- regmatch.regprog = vim_regcomp(pattern, RE_MAGIC);
+ {
+ if (prog != NULL)
+ regmatch.regprog = prog;
+ else
+ regmatch.regprog = vim_regcomp(pattern, RE_MAGIC);
+ }
/*
* Try for a match with the pattern with:
@@ -8633,7 +8644,8 @@
|| (!allow_dirs && vim_regexec(®match, tail, (colnr_T)0)))))
result = TRUE;
- vim_free(regmatch.regprog);
+ if (prog == NULL)
+ vim_free(regmatch.regprog);
return result;
}
#endif
@@ -8667,7 +8679,8 @@
regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE);
if (regpat == NULL)
break;
- match = match_file_pat(regpat, ffname, sfname, tail, (int)allow_dirs);
+ match = match_file_pat(regpat, NULL, ffname, sfname,
+ tail, (int)allow_dirs);
vim_free(regpat);
if (match)
return TRUE;