mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.1439: ga_grow(): 1.5x growth rate #10699
Problem: Json_encode() is very slow for large results.
Solution: In the growarray use a growth of at least 50%. (Ken Takata,
closes vim/vim#4461)
c47ed44be7
This commit is contained in:
parent
f5d1e0e7b1
commit
7086751c5e
@ -89,6 +89,14 @@ void ga_grow(garray_T *gap, int 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;
|
||||
}
|
||||
|
||||
int new_maxlen = gap->ga_len + n;
|
||||
|
||||
size_t new_size = (size_t)gap->ga_itemsize * (size_t)new_maxlen;
|
||||
|
Loading…
Reference in New Issue
Block a user