aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-08-05 17:42:41 -0400
committerJustin M. Keyes <justinkz@gmail.com>2019-08-05 23:42:41 +0200
commit7086751c5e4eb3cfee0b98df0d3cedc8bff47d35 (patch)
tree3b5393b61def49a9b3c9bc429d1c296e6680ba9b /src
parentf5d1e0e7b1837e8b76f1561167543c90a9942a7a (diff)
downloadrneovim-7086751c5e4eb3cfee0b98df0d3cedc8bff47d35.tar.gz
rneovim-7086751c5e4eb3cfee0b98df0d3cedc8bff47d35.tar.bz2
rneovim-7086751c5e4eb3cfee0b98df0d3cedc8bff47d35.zip
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) https://github.com/vim/vim/commit/c47ed44be76a520ded90913099771999c8a79eeb
Diffstat (limited to 'src')
-rw-r--r--src/nvim/garray.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/nvim/garray.c b/src/nvim/garray.c
index 74fd9d89cb..1cfc2b6176 100644
--- a/src/nvim/garray.c
+++ b/src/nvim/garray.c
@@ -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;