bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] fts: avoid unnecessary strlen calls


From: Bernhard Voelker
Subject: Re: [PATCH] fts: avoid unnecessary strlen calls
Date: Thu, 10 Apr 2014 07:50:35 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 04/09/2014 06:21 PM, Eric Blake wrote:
> On 04/09/2014 10:11 AM, Paul Eggert wrote:
>> Pádraig Brady wrote:
>>> But you're correct, so please push an adjustment,
>>> or I can handle it later.
>>
>> I installed it.
> 
> Almost - you forgot to revert the deletion of the fallback macro, so I
> fixed that.

Thanks you for fixing it.

For my own reference, this solution is exactly what is proposed
in <dirent.h> (on my Linux box):

  /* These macros extract size information from a `struct dirent *'.
     They may evaluate their argument multiple times, so it must not
     have side effects.  Each of these may involve a relatively costly
     call to `strlen' on some systems, so these values should be cached.

     _D_EXACT_NAMLEN (DP) returns the length of DP->d_name, not including
     its terminating null character.

     [...]
     */

  #ifdef _DIRENT_HAVE_D_NAMLEN
  # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
  [...]
  #else
  # define _D_EXACT_NAMLEN(d) (strlen ((d)->d_name))
  [...]
  # endif
  #endif

Thanks again & have a nice day,
Berny



reply via email to

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