diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-09 13:36:08 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-09 13:36:08 +0000 |
commit | 0ed913df7255ceabb3fdc3f90fcf6695811a03f5 (patch) | |
tree | 3f3533ea26a0ca00aae9d99a00acd04a96d64c91 /src/libutil/fstring.c | |
parent | baf80710bc92f6e989844764772a05c53f36c53a (diff) | |
download | rspamd-0ed913df7255ceabb3fdc3f90fcf6695811a03f5.tar.gz rspamd-0ed913df7255ceabb3fdc3f90fcf6695811a03f5.zip |
[Fix] Optimize rspamd_fstring_t reallocations
Diffstat (limited to 'src/libutil/fstring.c')
-rw-r--r-- | src/libutil/fstring.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index 8b5cae65b..65f24dccc 100644 --- a/src/libutil/fstring.c +++ b/src/libutil/fstring.c @@ -16,7 +16,11 @@ #include "fstring.h" #include "str_util.h" -static const gsize default_initial_size = 48; +#ifdef WITH_JEMALLOC +#include <jemalloc/jemalloc.h> +#endif + +static const gsize default_initial_size = 16; #define fstravail(s) ((s)->allocated - (s)->len) @@ -110,35 +114,12 @@ inline gsize rspamd_fstring_suggest_size (gsize len, gsize allocated, gsize needed_len) { gsize newlen; - /* Maximum size when we double the size of new string */ - static const gsize max_grow = 1024 * 1024; - - newlen = allocated; - - /* - * Stop exponential grow at some point, since it might be slow for the - * vast majority of cases - */ - if (newlen < max_grow) { - newlen *= 2; - } - else { - newlen += max_grow; - } - /* - * Check for overflow - */ - if (newlen <= len + needed_len) { - newlen = len + needed_len; + newlen = MAX (len + needed_len, 1 + allocated * 3 / 2); - if (newlen < max_grow) { - newlen *= 2; - } - else { - newlen += max_grow; - } - } +#ifdef WITH_JEMALLOC + newlen = nallocx (newlen + sizeof (rspamd_fstring_t), 0); +#endif return newlen; } |