summaryrefslogtreecommitdiff
path: root/src/misc2.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-06-01 14:36:26 +0200
committerBram Moolenaar <Bram@vim.org>2019-06-01 14:36:26 +0200
commitc47ed44be76a520ded90913099771999c8a79eeb (patch)
tree88923b515b01907520e70f721d6f1fffd0965589 /src/misc2.c
parent815b76bff618c07226653e11f29c4d3c5640b63a (diff)
downloadvim-git-c47ed44be76a520ded90913099771999c8a79eeb.tar.gz
patch 8.1.1439: json_encode() is very slow for large resultsv8.1.1439
Problem: Json_encode() is very slow for large results. Solution: In the growarray use a growth of at least 50%. (Ken Takata, closes #4461)
Diffstat (limited to 'src/misc2.c')
-rw-r--r--src/misc2.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/misc2.c b/src/misc2.c
index 461d23e9f..69b9347bc 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -2057,6 +2057,13 @@ 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;
+
new_len = gap->ga_itemsize * (gap->ga_len + n);
pp = vim_realloc(gap->ga_data, new_len);
if (pp == NULL)