On Sat, May 28, 2016 at 10:12:19PM -0400, DJ Delorie wrote: > > Alan Modra <amo...@gmail.com> writes: > > * xmemdup.c (xmemdup): Use xmalloc rather than xcalloc. > > In glibc at least, calloc can be faster than memset if the kernel is > pre-zero-ing pages. Thus, in those cases, your change makes the code > slower by adding an unneeded memset. Have you considered these cases?
Actually, I didn't consider that.. I was looking at usage of xmemdup in binutils, gdb and gcc, and noticed that a lot of the calls don't need to clear any memory, and those that do only need to clear at most two bytes. ie. All uses have alloc_size <= copy_size + 2. So in real-world usage of xmemdup, I think the possible gain of fresh sbrk memory resulting in no internal calloc memset is minimal at best and of course if calloc is reusing freed memory then it will internally memset to zero. -- Alan Modra Australia Development Lab, IBM