Hi

Attached patch speeds up function ga_grow() by
using realloc() instead of freeing and allocating
a new block when growing an array.  It should also
reduce memory usage.

Vim is 25% faster after patch with this test case:

$ wget http://dominique.pelle.free.fr/speed-join.vim.gz
$ gzip -d speed-join.vim.gz

$ time vim -u NONE -S speed-join.vim

3 measurements with vim-7.3.444 _before_ patch:

  22.252 sec
  23.094 sec
  22.748 sec

3 measurements with vim-7.3.444 _after_ patch:

  16.509 sec
  16.342 sec
  16.077 sec

That's ~25% faster.

ga_grow() is used for many things in Vim
so there might be other things that are also faster.

Regards
-- Dominique

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r b37888de599c src/misc2.c
--- a/src/misc2.c	Mon Feb 13 00:05:22 2012 +0100
+++ b/src/misc2.c	Mon Feb 13 19:51:01 2012 +0100
@@ -2064,24 +2064,22 @@
     garray_T	*gap;
     int		n;
 {
-    size_t	len;
+    size_t	old_len;
+    size_t	new_len;
     char_u	*pp;
 
     if (gap->ga_maxlen - gap->ga_len < n)
     {
 	if (n < gap->ga_growsize)
 	    n = gap->ga_growsize;
-	len = gap->ga_itemsize * (gap->ga_len + n);
-	pp = alloc_clear((unsigned)len);
+	new_len = gap->ga_itemsize * (gap->ga_len + n);
+	pp = (gap->ga_data == NULL) ?
+	    alloc(new_len) : vim_realloc(gap->ga_data, new_len);
 	if (pp == NULL)
 	    return FAIL;
+	old_len = gap->ga_itemsize * gap->ga_maxlen;
+	vim_memset(pp + old_len, 0, new_len - old_len);
 	gap->ga_maxlen = gap->ga_len + n;
-	if (gap->ga_data != NULL)
-	{
-	    mch_memmove(pp, gap->ga_data,
-				      (size_t)(gap->ga_itemsize * gap->ga_len));
-	    vim_free(gap->ga_data);
-	}
 	gap->ga_data = pp;
     }
     return OK;

Raspunde prin e-mail lui