Skip to content

Commit 462455e

Browse files
committed
patch 8.0.1284: loading file type detection slows down startup
Problem: Loading file type detection slows down startup. Solution: Store the last pattern of an autocommand event to make appending quicker.
1 parent 9ed7d34 commit 462455e

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/fileio.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7650,6 +7650,8 @@ forward_slash(char_u *fname)
76507650
* together, to avoid having to match the pattern too often.
76517651
* The result is an array of Autopat lists, which point to AutoCmd lists:
76527652
*
7653+
* last_autopat[0] -----------------------------+
7654+
* V
76537655
* first_autopat[0] --> Autopat.next --> Autopat.next --> NULL
76547656
* Autopat.cmds Autopat.cmds
76557657
* | |
@@ -7662,6 +7664,8 @@ forward_slash(char_u *fname)
76627664
* V
76637665
* NULL
76647666
*
7667+
* last_autopat[1] --------+
7668+
* V
76657669
* first_autopat[1] --> Autopat.next --> NULL
76667670
* Autopat.cmds
76677671
* |
@@ -7689,11 +7693,12 @@ typedef struct AutoCmd
76897693

76907694
typedef struct AutoPat
76917695
{
7696+
struct AutoPat *next; /* next AutoPat in AutoPat list; MUST
7697+
* be the first entry */
76927698
char_u *pat; /* pattern as typed (NULL when pattern
76937699
has been removed) */
76947700
regprog_T *reg_prog; /* compiled regprog for pattern */
76957701
AutoCmd *cmds; /* list of commands to do */
7696-
struct AutoPat *next; /* next AutoPat in AutoPat list */
76977702
int group; /* group ID */
76987703
int patlen; /* strlen() of pat */
76997704
int buflocal_nr; /* !=0 for buffer-local AutoPat */
@@ -7813,6 +7818,16 @@ static AutoPat *first_autopat[NUM_EVENTS] =
78137818
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
78147819
};
78157820

7821+
static AutoPat *last_autopat[NUM_EVENTS] =
7822+
{
7823+
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7824+
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7825+
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7826+
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7827+
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7828+
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
7829+
};
7830+
78167831
/*
78177832
* struct used to keep status while executing autocommands for an event.
78187833
*/
@@ -8011,6 +8026,15 @@ au_cleanup(void)
80118026
/* remove the pattern if it has been marked for deletion */
80128027
if (ap->pat == NULL)
80138028
{
8029+
if (ap->next == NULL)
8030+
{
8031+
if (prev_ap == &(first_autopat[(int)event]))
8032+
last_autopat[(int)event] = NULL;
8033+
else
8034+
/* this depends on the "next" field being the first in
8035+
* the struct */
8036+
last_autopat[(int)event] = (AutoPat *)prev_ap;
8037+
}
80148038
*prev_ap = ap->next;
80158039
vim_regfree(ap->reg_prog);
80168040
vim_free(ap);
@@ -8675,9 +8699,13 @@ do_autocmd_event(
86758699
}
86768700

86778701
/*
8678-
* Find AutoPat entries with this pattern.
8702+
* Find AutoPat entries with this pattern. When adding a command it
8703+
* always goes at or after the last one, so start at the end.
86798704
*/
8680-
prev_ap = &first_autopat[(int)event];
8705+
if (!forceit && *cmd != NUL && last_autopat[(int)event] != NULL)
8706+
prev_ap = &last_autopat[(int)event];
8707+
else
8708+
prev_ap = &first_autopat[(int)event];
86818709
while ((ap = *prev_ap) != NULL)
86828710
{
86838711
if (ap->pat != NULL)
@@ -8783,6 +8811,7 @@ do_autocmd_event(
87838811
}
87848812
ap->cmds = NULL;
87858813
*prev_ap = ap;
8814+
last_autopat[(int)event] = ap;
87868815
ap->next = NULL;
87878816
if (group == AUGROUP_ALL)
87888817
ap->group = current_augroup;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1284,
764766
/**/
765767
1283,
766768
/**/

0 commit comments

Comments
 (0)