]> git.pld-linux.org Git - packages/vim.git/blob - 7.1.235
- updated to 7.1.285
[packages/vim.git] / 7.1.235
1 To: vim-dev@vim.org
2 Subject: Patch 7.1.235
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.1.235
11 Problem:    Pattern matching is slow when using a lot of simple patterns.
12 Solution:   Avoid allocating memory by not freeing it when it's not so much.
13             (Alexei Alexandrov)
14 Files:      src/regexp.c
15
16
17 *** ../vim-7.1.234/src/regexp.c Wed Jan  2 15:34:48 2008
18 --- src/regexp.c        Fri Jan 18 20:35:21 2008
19 ***************
20 *** 378,391 ****
21   
22   static char_u         *reg_prev_sub = NULL;
23   
24 - #if defined(EXITFREE) || defined(PROTO)
25 -     void
26 - free_regexp_stuff()
27 - {
28 -     vim_free(reg_prev_sub);
29 - }
30 - #endif
31
32   /*
33    * REGEXP_INRANGE contains all characters which are always special in a []
34    * range after '\'.
35 --- 378,383 ----
36 ***************
37 *** 3206,3217 ****
38   } backpos_T;
39   
40   /*
41 !  * regstack and backpos are used by regmatch().  They are kept over calls to
42 !  * avoid invoking malloc() and free() often.
43    */
44 ! static garray_T       regstack;       /* stack with regitem_T items, sometimes
45 !                                  preceded by regstar_T or regbehind_T. */
46 ! static garray_T       backpos;        /* table with backpos_T for BACK */
47   
48   /*
49    * Get pointer to the line "lnum", which is relative to "reg_firstlnum".
50 --- 3198,3236 ----
51   } backpos_T;
52   
53   /*
54 !  * "regstack" and "backpos" are used by regmatch().  They are kept over calls
55 !  * to avoid invoking malloc() and free() often.
56 !  * "regstack" is a stack with regitem_T items, sometimes preceded by regstar_T
57 !  * or regbehind_T.
58 !  * "backpos_T" is a table with backpos_T for BACK
59 !  */
60 ! static garray_T       regstack = {0, 0, 0, 0, NULL};
61 ! static garray_T       backpos = {0, 0, 0, 0, NULL};
62
63 ! /*
64 !  * Both for regstack and backpos tables we use the following strategy of
65 !  * allocation (to reduce malloc/free calls):
66 !  * - Initial size is fairly small.
67 !  * - When needed, the tables are grown bigger (8 times at first, double after
68 !  *   that).
69 !  * - After executing the match we free the memory only if the array has grown.
70 !  *   Thus the memory is kept allocated when it's at the initial size.
71 !  * This makes it fast while not keeping a lot of memory allocated.
72 !  * A three times speed increase was observed when using many simple patterns.
73    */
74 ! #define REGSTACK_INITIAL      2048
75 ! #define BACKPOS_INITIAL               64
76
77 ! #if defined(EXITFREE) || defined(PROTO)
78 !     void
79 ! free_regexp_stuff()
80 ! {
81 !     ga_clear(&regstack);
82 !     ga_clear(&backpos);
83 !     vim_free(reg_tofree);
84 !     vim_free(reg_prev_sub);
85 ! }
86 ! #endif
87   
88   /*
89    * Get pointer to the line "lnum", which is relative to "reg_firstlnum".
90 ***************
91 *** 3346,3360 ****
92       char_u    *s;
93       long      retval = 0L;
94   
95 !     reg_tofree = NULL;
96
97 !     /* Init the regstack empty.  Use an item size of 1 byte, since we push
98 !      * different things onto it.  Use a large grow size to avoid reallocating
99 !      * it too often. */
100 !     ga_init2(&regstack, 1, 10000);
101
102 !     /* Init the backpos table empty. */
103 !     ga_init2(&backpos, sizeof(backpos_T), 10);
104   
105       if (REG_MULTI)
106       {
107 --- 3365,3389 ----
108       char_u    *s;
109       long      retval = 0L;
110   
111 !     /* Create "regstack" and "backpos" if they are not allocated yet.
112 !      * We allocate *_INITIAL amount of bytes first and then set the grow size
113 !      * to much bigger value to avoid many malloc calls in case of deep regular
114 !      * expressions.  */
115 !     if (regstack.ga_data == NULL)
116 !     {
117 !       /* Use an item size of 1 byte, since we push different things
118 !        * onto the regstack. */
119 !       ga_init2(&regstack, 1, REGSTACK_INITIAL);
120 !       ga_grow(&regstack, REGSTACK_INITIAL);
121 !       regstack.ga_growsize = REGSTACK_INITIAL * 8;
122 !     }
123
124 !     if (backpos.ga_data == NULL)
125 !     {
126 !       ga_init2(&backpos, sizeof(backpos_T), BACKPOS_INITIAL);
127 !       ga_grow(&backpos, BACKPOS_INITIAL);
128 !       backpos.ga_growsize = BACKPOS_INITIAL * 8;
129 !     }
130   
131       if (REG_MULTI)
132       {
133 ***************
134 *** 3525,3533 ****
135       }
136   
137   theend:
138 !     vim_free(reg_tofree);
139 !     ga_clear(&regstack);
140 !     ga_clear(&backpos);
141   
142       return retval;
143   }
144 --- 3554,3570 ----
145       }
146   
147   theend:
148 !     /* Free "reg_tofree" when it's a bit big.
149 !      * Free regstack and backpos if they are bigger than their initial size. */
150 !     if (reg_tofreelen > 400)
151 !     {
152 !       vim_free(reg_tofree);
153 !       reg_tofree = NULL;
154 !     }
155 !     if (regstack.ga_maxlen > REGSTACK_INITIAL)
156 !       ga_clear(&regstack);
157 !     if (backpos.ga_maxlen > BACKPOS_INITIAL)
158 !       ga_clear(&backpos);
159   
160       return retval;
161   }
162 ***************
163 *** 3717,3724 ****
164   #define RA_MATCH      4       /* successful match */
165   #define RA_NOMATCH    5       /* didn't match */
166   
167 !   /* Init the regstack and backpos table empty.  They are initialized and
168 !    * freed in vim_regexec_both() to reduce malloc()/free() calls. */
169     regstack.ga_len = 0;
170     backpos.ga_len = 0;
171   
172 --- 3754,3761 ----
173   #define RA_MATCH      4       /* successful match */
174   #define RA_NOMATCH    5       /* didn't match */
175   
176 !   /* Make "regstack" and "backpos" empty.  They are allocated and freed in
177 !    * vim_regexec_both() to reduce malloc()/free() calls. */
178     regstack.ga_len = 0;
179     backpos.ga_len = 0;
180   
181 *** ../vim-7.1.234/src/version.c        Fri Jan 18 17:39:10 2008
182 --- src/version.c       Fri Jan 18 20:33:26 2008
183 ***************
184 *** 668,669 ****
185 --- 668,671 ----
186   {   /* Add new patch number below this line */
187 + /**/
188 +     235,
189   /**/
190
191 -- 
192 NEIL INNES PLAYED: THE FIRST SELF-DESTRUCTIVE MONK, ROBIN'S LEAST FAVORITE
193                    MINSTREL, THE PAGE CRUSHED BY A RABBIT, THE OWNER OF A DUCK
194                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
195
196  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
197 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
198 \\\        download, build and distribute -- http://www.A-A-P.org        ///
199  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
This page took 0.044528 seconds and 3 git commands to generate.