[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] fts: avoid unnecessary strlen calls
From: |
Pádraig Brady |
Subject: |
Re: [PATCH] fts: avoid unnecessary strlen calls |
Date: |
Wed, 09 Apr 2014 16:55:17 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 |
On 04/09/2014 04:47 PM, Eric Blake wrote:
> 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
> defined?
>
>
>>
>> - 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.
I've already pushed.
But you're correct, so please push an adjustment,
or I can handle it later.
thanks,
Pádraig.