]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.1439: json_encode() is very slow for large results v8.1.1439
authorBram Moolenaar <Bram@vim.org>
Sat, 1 Jun 2019 12:36:26 +0000 (14:36 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 1 Jun 2019 12:36:26 +0000 (14:36 +0200)
Problem:    Json_encode() is very slow for large results.
Solution:   In the growarray use a growth of at least 50%. (Ken Takata,
            closes #4461)

src/misc2.c
src/version.c

index 461d23e9fc67adec8dcbf761f7f8ec2f08e3e3ae..69b9347bcba7c2b9c6513d95f7d8e76294d39f5e 100644 (file)
@@ -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)
index 4b380d2726f693b4a5ec9cc50e336e9353db7f69..30c0831078a7cf990aaccf2828b64365cb5cb7d2 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1439,
 /**/
     1438,
 /**/