Re: [PATCH 1/3] match_pathname: avoid calling strncmp if baselen is 0
- From
Antoine Pelisse <apelisse@gmail.com>
- Date
- Mar 9, 2013, 09:06 UTC
- Message-ID
- <CALWbr2xJfgba9_nyy609mhMOY3vq_ckZwb5C2nSsZJNNFRCLTA@mail.gmail.com>
- In-Reply-To
- <1362802190-7331-2-git-send-email-pclouds@gmail.com>
Show 10 quoted lines
> diff --git a/dir.c b/dir.c > index 57394e4..669cf80 100644 > --- a/dir.c > +++ b/dir.c > @@ -663,7 +663,7 @@ int match_pathname(const char *pathname, int pathlen, > */ > if (pathlen < baselen + 1 || > (baselen && pathname[baselen] != '/') || > - strncmp_icase(pathname, base, baselen)) > + (baselen && strncmp_icase(pathname, base, baselen)))
Shouldn't you factorize by baselen here ? For readability reasons, not performance of course.
> return 0; > > namelen = baselen ? pathlen - baselen - 1 : pathlen;