home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.1 / 7.1.235 < prev    next >
Encoding:
Internet Message Format  |  2008-01-17  |  5.8 KB

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