avoid calling strlen() twice in readlink()

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Mar 8 15:56:00 GMT 2012


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



More information about the Cygwin-patches mailing list