[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] fts: avoid unnecessary strlen calls

From: Eric Blake
Subject: Re: [PATCH] fts: avoid unnecessary strlen calls
Date: Wed, 09 Apr 2014 09:47:59 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

On 04/09/2014 06:25 AM, Bernhard Voelker wrote:
> I was wondering why strlen() showed up over 3M times when
> running "rm -rf some-dir" - where "some-dir" contained 1M files.
> This was shown by "ltrace -c ...".
> The attached avoids 2M strlen() invocations for this case.

>  #include <dirent.h>
> -#ifndef _D_EXACT_NAMLEN
> -# define _D_EXACT_NAMLEN(dirent) strlen ((dirent)->d_name)
> -#endif

Doesn't _D_EXACT_NAMLEN avoid a strlen() call on platforms where it is

> -                if ((p = fts_alloc (sp, dp->d_name,
> -                                    _D_EXACT_NAMLEN (dp))) == NULL)
> +                namlen = strlen (dp->d_name);

In other words, I think it still might sense to do:

namlen = _D_EXACT_NAMLEN (dp);

then use namlen everywhere else, rather than blindly calling strlen(),
for the case where _D_EXACT_NAMLEN also shaves a call.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]