This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Make memset in calloc a tail call.
- From: Andrew Pinski <pinskia at gmail dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 7 Nov 2013 12:39:46 -0800
- Subject: Re: [PATCH] Make memset in calloc a tail call.
- Authentication-results: sourceware.org; auth=none
- References: <20131107203149 dot GA21816 at domone>
On Thu, Nov 7, 2013 at 12:31 PM, OndÅej BÃlka <neleai@seznam.cz> wrote:
> Hi, after reading a calloc code I found that we do not return memset
> value. Unless compiler can recognize that memset result and return value
> are same it will be used as normal call but a tail call is faster.
It can and does in 4.8 and above but that is after the tail call
optimization happens.
Thanks,
Andrew Pinski
>
> OK to commit?
>
> * malloc/malloc.c (calloc): Make memset a tail call.
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 897c43a..3fac780 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -3214,7 +3214,7 @@ __libc_calloc(size_t n, size_t elem_size)
> if (chunk_is_mmapped (p))
> {
> if (__builtin_expect (perturb_byte, 0))
> - MALLOC_ZERO (mem, sz);
> + return MALLOC_ZERO (mem, sz);
> return mem;
> }
>
> @@ -3236,7 +3236,7 @@ __libc_calloc(size_t n, size_t elem_size)
> assert(nclears >= 3);
>
> if (nclears > 9)
> - MALLOC_ZERO(d, clearsize);
> + return MALLOC_ZERO(d, clearsize);
>
> else {
> *(d+0) = 0;