Skip to content

Commit

Permalink
lib: Implement i_realloc(mem==NULL) more efficiently
Browse files Browse the repository at this point in the history
Various parts of code use this to allocate the initial buffer. We can
do this more efficiently by using calloc().
  • Loading branch information
sirainen committed Apr 29, 2016
1 parent 62219bb commit 81bbb8e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/mempool-system.c
Expand Up @@ -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));
Expand Down

0 comments on commit 81bbb8e

Please sign in to comment.