Mercurial > vim
comparison src/misc2.c @ 16876:cdca5f577c36 v8.1.1439
patch 8.1.1439: json_encode() is very slow for large results
commit https://github.com/vim/vim/commit/c47ed44be76a520ded90913099771999c8a79eeb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 1 14:36:26 2019 +0200
patch 8.1.1439: json_encode() is very slow for large results
Problem: Json_encode() is very slow for large results.
Solution: In the growarray use a growth of at least 50%. (Ken Takata,
closes #4461)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 01 Jun 2019 14:45:04 +0200 |
parents | ce04ebdf26b8 |
children | 998603a243d7 |
comparison
equal
deleted
inserted
replaced
16875:df19064e8d01 | 16876:cdca5f577c36 |
---|---|
2055 | 2055 |
2056 if (gap->ga_maxlen - gap->ga_len < n) | 2056 if (gap->ga_maxlen - gap->ga_len < n) |
2057 { | 2057 { |
2058 if (n < gap->ga_growsize) | 2058 if (n < gap->ga_growsize) |
2059 n = gap->ga_growsize; | 2059 n = gap->ga_growsize; |
2060 | |
2061 // A linear growth is very inefficient when the array grows big. This | |
2062 // is a compromise between allocating memory that won't be used and too | |
2063 // many copy operations. A factor of 1.5 seems reasonable. | |
2064 if (n < gap->ga_len / 2) | |
2065 n = gap->ga_len / 2; | |
2066 | |
2060 new_len = gap->ga_itemsize * (gap->ga_len + n); | 2067 new_len = gap->ga_itemsize * (gap->ga_len + n); |
2061 pp = vim_realloc(gap->ga_data, new_len); | 2068 pp = vim_realloc(gap->ga_data, new_len); |
2062 if (pp == NULL) | 2069 if (pp == NULL) |
2063 return FAIL; | 2070 return FAIL; |
2064 old_len = gap->ga_itemsize * gap->ga_maxlen; | 2071 old_len = gap->ga_itemsize * gap->ga_maxlen; |