summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-11-10 21:53:11 +0100
committerBram Moolenaar <Bram@vim.org>2017-11-10 21:53:11 +0100
commit462455ee8b81cb5709007d91248ac4a88308d6e9 (patch)
tree664c2ac77285b4225f639c645fe46033aaaa49e2
parent9ed7d34af303190bb222624157e0c6cd78b7d120 (diff)
downloadvim-git-462455ee8b81cb5709007d91248ac4a88308d6e9.tar.gz
patch 8.0.1284: loading file type detection slows down startupv8.0.1284
Problem: Loading file type detection slows down startup. Solution: Store the last pattern of an autocommand event to make appending quicker.
-rw-r--r--src/fileio.c35
-rw-r--r--src/version.c2
2 files changed, 34 insertions, 3 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 400ad87b1..d991822c3 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7650,6 +7650,8 @@ forward_slash(char_u *fname)
* together, to avoid having to match the pattern too often.
* The result is an array of Autopat lists, which point to AutoCmd lists:
*
+ * last_autopat[0] -----------------------------+
+ * V
* first_autopat[0] --> Autopat.next --> Autopat.next --> NULL
* Autopat.cmds Autopat.cmds
* | |
@@ -7662,6 +7664,8 @@ forward_slash(char_u *fname)
* V
* NULL
*
+ * last_autopat[1] --------+
+ * V
* first_autopat[1] --> Autopat.next --> NULL
* Autopat.cmds
* |
@@ -7689,11 +7693,12 @@ typedef struct AutoCmd
typedef struct AutoPat
{
+ struct AutoPat *next; /* next AutoPat in AutoPat list; MUST
+ * be the first entry */
char_u *pat; /* pattern as typed (NULL when pattern
has been removed) */
regprog_T *reg_prog; /* compiled regprog for pattern */
AutoCmd *cmds; /* list of commands to do */
- struct AutoPat *next; /* next AutoPat in AutoPat list */
int group; /* group ID */
int patlen; /* strlen() of pat */
int buflocal_nr; /* !=0 for buffer-local AutoPat */
@@ -7813,6 +7818,16 @@ static AutoPat *first_autopat[NUM_EVENTS] =
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
+static AutoPat *last_autopat[NUM_EVENTS] =
+{
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
/*
* struct used to keep status while executing autocommands for an event.
*/
@@ -8011,6 +8026,15 @@ au_cleanup(void)
/* remove the pattern if it has been marked for deletion */
if (ap->pat == NULL)
{
+ if (ap->next == NULL)
+ {
+ if (prev_ap == &(first_autopat[(int)event]))
+ last_autopat[(int)event] = NULL;
+ else
+ /* this depends on the "next" field being the first in
+ * the struct */
+ last_autopat[(int)event] = (AutoPat *)prev_ap;
+ }
*prev_ap = ap->next;
vim_regfree(ap->reg_prog);
vim_free(ap);
@@ -8675,9 +8699,13 @@ do_autocmd_event(
}
/*
- * Find AutoPat entries with this pattern.
+ * Find AutoPat entries with this pattern. When adding a command it
+ * always goes at or after the last one, so start at the end.
*/
- prev_ap = &first_autopat[(int)event];
+ if (!forceit && *cmd != NUL && last_autopat[(int)event] != NULL)
+ prev_ap = &last_autopat[(int)event];
+ else
+ prev_ap = &first_autopat[(int)event];
while ((ap = *prev_ap) != NULL)
{
if (ap->pat != NULL)
@@ -8783,6 +8811,7 @@ do_autocmd_event(
}
ap->cmds = NULL;
*prev_ap = ap;
+ last_autopat[(int)event] = ap;
ap->next = NULL;
if (group == AUGROUP_ALL)
ap->group = current_augroup;
diff --git a/src/version.c b/src/version.c
index c74f06251..65cc66f31 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1284,
+/**/
1283,
/**/
1282,