]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Implement i_realloc(mem==NULL) more efficiently
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Apr 2016 09:54:46 +0000 (12:54 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Apr 2016 09:54:46 +0000 (12:54 +0300)
Various parts of code use this to allocate the initial buffer. We can
do this more efficiently by using calloc().

src/lib/mempool-system.c

index ab83e22310c0088b9c218e6eb9a4839b74110072..2cc5d3ae6f6b3ec84c017c225047c9bf19e909af 100644 (file)
@@ -119,6 +119,10 @@ static void *pool_system_realloc(pool_t pool ATTR_UNUSED, void *mem,
        if (unlikely(new_size == 0 || new_size > SSIZE_T_MAX))
                i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size);
 
+       if (mem == NULL) {
+               i_assert(old_size == 0);
+               return pool_system_malloc(pool, new_size);
+       }
 #if !defined(USE_GC) && defined(HAVE_MALLOC_USABLE_SIZE)
        i_assert(old_size == (size_t)-1 || mem == NULL ||
                 old_size <= malloc_usable_size(mem));