0
0
mirror of https://github.com/vim/vim.git synced 2025-10-01 04:54:07 -04:00

patch 8.2.0751: Vim9: performance can be improved

Problem:    Vim9: performance can be improved.
Solution:   Don't call break.  Inline check for list materialize.  Make an
            inline version of ga_grow().
This commit is contained in:
Bram Moolenaar
2020-05-13 22:44:22 +02:00
parent 37d1b4f941
commit 7e9f351b2e
17 changed files with 89 additions and 79 deletions

View File

@@ -2053,31 +2053,36 @@ ga_init2(garray_T *gap, int itemsize, int growsize)
*/
int
ga_grow(garray_T *gap, int n)
{
if (gap->ga_maxlen - gap->ga_len < n)
return ga_grow_inner(gap, n);
return OK;
}
int
ga_grow_inner(garray_T *gap, int n)
{
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;
if (n < gap->ga_growsize)
n = gap->ga_growsize;
// A linear growth is very inefficient when the array grows big. This
// is a compromise between allocating memory that won't be used and too
// many copy operations. A factor of 1.5 seems reasonable.
if (n < gap->ga_len / 2)
n = gap->ga_len / 2;
// A linear growth is very inefficient when the array grows big. This
// is a compromise between allocating memory that won't be used and too
// many copy operations. A factor of 1.5 seems reasonable.
if (n < gap->ga_len / 2)
n = gap->ga_len / 2;
new_len = gap->ga_itemsize * (gap->ga_len + n);
pp = 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;
gap->ga_data = pp;
}
new_len = gap->ga_itemsize * (gap->ga_len + n);
pp = 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;
gap->ga_data = pp;
return OK;
}