To: vim_dev@googlegroups.com Subject: Patch 8.0.1284 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1284 Problem: Loading file type detection slows down startup. Solution: Store the last pattern of an autocommand event to make appending quicker. Files: src/fileio.c *** ../vim-8.0.1283/src/fileio.c 2017-11-09 12:29:27.390551291 +0100 --- src/fileio.c 2017-11-10 21:32:24.728163773 +0100 *************** *** 7650,7655 **** --- 7650,7657 ---- * 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,7667 **** --- 7664,7671 ---- * V * NULL * + * last_autopat[1] --------+ + * V * first_autopat[1] --> Autopat.next --> NULL * Autopat.cmds * | *************** *** 7689,7699 **** typedef struct AutoPat { 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 */ --- 7693,7704 ---- 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 */ int group; /* group ID */ int patlen; /* strlen() of pat */ int buflocal_nr; /* !=0 for buffer-local AutoPat */ *************** *** 7813,7818 **** --- 7818,7833 ---- 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,8016 **** --- 8026,8040 ---- /* 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,8683 **** } /* ! * Find AutoPat entries with this pattern. */ ! prev_ap = &first_autopat[(int)event]; while ((ap = *prev_ap) != NULL) { if (ap->pat != NULL) --- 8699,8711 ---- } /* ! * Find AutoPat entries with this pattern. When adding a command it ! * always goes at or after the last one, so start at the end. */ ! 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,8788 **** --- 8811,8817 ---- } ap->cmds = NULL; *prev_ap = ap; + last_autopat[(int)event] = ap; ap->next = NULL; if (group == AUGROUP_ALL) ap->group = current_augroup; *** ../vim-8.0.1283/src/version.c 2017-11-09 22:10:29.188559134 +0100 --- src/version.c 2017-11-10 21:51:03.811958628 +0100 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1284, /**/ -- "Lisp has all the visual appeal of oatmeal with nail clippings thrown in." -- Larry Wall /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///