]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
string-util: use GREEDY_ALLOC_ROUND_UP() in strextend() 18150/head
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Jan 2021 16:23:38 +0000 (17:23 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 6 Jan 2021 16:25:12 +0000 (17:25 +0100)
This uses GREEDY_ALLOC_ROUND_UP() to grow the allocation size
exponentially. This should speed allocation loops up a bit, given
that we often call strextend() repeatedly in a loop on the same
buffer.

src/basic/string-util.c

index 105952156d7512890a3e8fbb43ef66fbeb5e3127..be42d5c4f5ddff82a78e13a729b3599770dd8557 100644 (file)
@@ -830,7 +830,7 @@ char *strextend_with_separator_internal(char **x, const char *separator, ...) {
 
         need_separator = !isempty(*x);
 
-        nr = realloc(*x, l+1);
+        nr = realloc(*x, GREEDY_ALLOC_ROUND_UP(l+1));
         if (!nr)
                 return NULL;