Mercurial > vim
diff src/misc2.c @ 20392:4c317d8c1051 v8.2.0751
patch 8.2.0751: Vim9: performance can be improved
Commit: https://github.com/vim/vim/commit/7e9f351b2e69b498c4ee5004d7459844e1ba191a
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed May 13 22:44:22 2020 +0200
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().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 13 May 2020 22:45:04 +0200 |
parents | 42ab4d40e78f |
children | c2570baa2e4c |
line wrap: on
line diff
--- a/src/misc2.c +++ b/src/misc2.c @@ -2054,30 +2054,35 @@ ga_init2(garray_T *gap, int itemsize, in 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; - - // 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; - } + 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; + + 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; }