This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: avoid calling strlen() twice in readlink()


On Mar  8 08:29, Eric Blake wrote:
> On 03/08/2012 06:37 AM, VÃclav Zeman wrote:
> > Hi.
> > 
> > Here is a tiny patch to avoid calling strlen() twice in readlink().
> > 
> 
> >  
> > -  ssize_t len = min (buflen, strlen (pathbuf.get_win32 ()));
> > +  size_t pathbuf_len = strlen (pathbuf.get_win32 ());
> > +  size_t len = MIN (buflen, pathbuf_len);
> >    memcpy (buf, pathbuf.get_win32 (), len);
> 
> For that matter, is calling pathbuf.get_win32() twice worth factoring out?

It's just a const char *pointer, and it's an inline method.  I'm pretty
sure the compiler will optimize this just fine.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]