different scaling for memory allocation - json2tsv - JSON to TSV converter
 (HTM) git clone git://git.codemadness.org/json2tsv
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f8704af3ceec42fb7be10caca4392c85f82631eb
 (DIR) parent dfd26e7ccf4f83f4c140503b69d773b1dbb81808
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Tue, 15 Oct 2019 18:43:56 +0200
       
       different scaling for memory allocation
       
       greedier for large strings, much less memory for smaller ones
       
       Diffstat:
         M json2tsv.c                          |       4 ++--
       
       1 file changed, 2 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/json2tsv.c b/json2tsv.c
       @@ -87,10 +87,10 @@ capacity(char **value, size_t *sz, size_t cur, size_t inc)
                need = cur + inc;
        
                if (need > *sz) {
       -                if (need > SIZE_MAX - 4096) {
       +                if (need > SIZE_MAX / 2) {
                                newsiz = SIZE_MAX;
                        } else {
       -                        for (newsiz = *sz; newsiz < need; newsiz += 4096)
       +                        for (newsiz = *sz < 64 ? 64 : *sz; newsiz <= need; newsiz *= 2)
                                        ;
                        }
                        if (!(newp = realloc(*value, newsiz)))