Karsten Hopp 6e6846
To: vim_dev@googlegroups.com
Karsten Hopp 6e6846
Subject: Patch 7.4.499
Karsten Hopp 6e6846
Fcc: outbox
Karsten Hopp 6e6846
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 6e6846
Mime-Version: 1.0
Karsten Hopp 6e6846
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 6e6846
Content-Transfer-Encoding: 8bit
Karsten Hopp 6e6846
------------
Karsten Hopp 6e6846
Karsten Hopp 6e6846
Patch 7.4.499
Karsten Hopp 6e6846
Problem:    substitute() can be slow with long strings.
Karsten Hopp 6e6846
Solution:   Store a pointer to the end, instead of calling strlen() every
Karsten Hopp 6e6846
	    time. (Ozaki Kiichi)
Karsten Hopp 6e6846
Files:	    src/eval.c
Karsten Hopp 6e6846
Karsten Hopp 6e6846
Karsten Hopp 6e6846
*** ../vim-7.4.498/src/eval.c	2014-10-31 15:45:49.171053328 +0100
Karsten Hopp 6e6846
--- src/eval.c	2014-11-05 15:49:49.040637923 +0100
Karsten Hopp 6e6846
***************
Karsten Hopp 6e6846
*** 25076,25081 ****
Karsten Hopp 6e6846
--- 25076,25082 ----
Karsten Hopp 6e6846
      int		i;
Karsten Hopp 6e6846
      int		do_all;
Karsten Hopp 6e6846
      char_u	*tail;
Karsten Hopp 6e6846
+     char_u	*end;
Karsten Hopp 6e6846
      garray_T	ga;
Karsten Hopp 6e6846
      char_u	*ret;
Karsten Hopp 6e6846
      char_u	*save_cpo;
Karsten Hopp 6e6846
***************
Karsten Hopp 6e6846
*** 25094,25099 ****
Karsten Hopp 6e6846
--- 25095,25101 ----
Karsten Hopp 6e6846
      if (regmatch.regprog != NULL)
Karsten Hopp 6e6846
      {
Karsten Hopp 6e6846
  	tail = str;
Karsten Hopp 6e6846
+ 	end = str + STRLEN(str);
Karsten Hopp 6e6846
  	while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
Karsten Hopp 6e6846
  	{
Karsten Hopp 6e6846
  	    /* Skip empty match except for first match. */
Karsten Hopp 6e6846
***************
Karsten Hopp 6e6846
*** 25120,25126 ****
Karsten Hopp 6e6846
  	     * - The text after the match.
Karsten Hopp 6e6846
  	     */
Karsten Hopp 6e6846
  	    sublen = vim_regsub(&regmatch, sub, tail, FALSE, TRUE, FALSE);
Karsten Hopp 6e6846
! 	    if (ga_grow(&ga, (int)(STRLEN(tail) + sublen -
Karsten Hopp 6e6846
  			    (regmatch.endp[0] - regmatch.startp[0]))) == FAIL)
Karsten Hopp 6e6846
  	    {
Karsten Hopp 6e6846
  		ga_clear(&ga);
Karsten Hopp 6e6846
--- 25122,25128 ----
Karsten Hopp 6e6846
  	     * - The text after the match.
Karsten Hopp 6e6846
  	     */
Karsten Hopp 6e6846
  	    sublen = vim_regsub(&regmatch, sub, tail, FALSE, TRUE, FALSE);
Karsten Hopp 6e6846
! 	    if (ga_grow(&ga, (int)((end - tail) + sublen -
Karsten Hopp 6e6846
  			    (regmatch.endp[0] - regmatch.startp[0]))) == FAIL)
Karsten Hopp 6e6846
  	    {
Karsten Hopp 6e6846
  		ga_clear(&ga);
Karsten Hopp 6e6846
*** ../vim-7.4.498/src/version.c	2014-11-05 15:46:06.212643292 +0100
Karsten Hopp 6e6846
--- src/version.c	2014-11-05 15:50:52.880636385 +0100
Karsten Hopp 6e6846
***************
Karsten Hopp 6e6846
*** 743,744 ****
Karsten Hopp 6e6846
--- 743,746 ----
Karsten Hopp 6e6846
  {   /* Add new patch number below this line */
Karsten Hopp 6e6846
+ /**/
Karsten Hopp 6e6846
+     499,
Karsten Hopp 6e6846
  /**/
Karsten Hopp 6e6846
Karsten Hopp 6e6846
-- 
Karsten Hopp 6e6846
ARTHUR:        A scratch?  Your arm's off!
Karsten Hopp 6e6846
BLACK KNIGHT:  No, it isn't.
Karsten Hopp 6e6846
ARTHUR:        Well, what's that then?
Karsten Hopp 6e6846
BLACK KNIGHT:  I've had worse.
Karsten Hopp 6e6846
                                  The Quest for the Holy Grail (Monty Python)
Karsten Hopp 6e6846
Karsten Hopp 6e6846
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 6e6846
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 6e6846
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 6e6846
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///