Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-12 Thread Duy Nguyen
On Wed, Mar 13, 2013 at 3:59 AM, Junio C Hamano wrote: >>> strncmp is provided length information which could be taken advantage >>> by the underlying implementation. > > After all, strcmp() could also be optimized to fetch word-at-a-time > while being careful about not overstepping the page bound

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-12 Thread Junio C Hamano
Duy Nguyen writes: > glibc's C strncmp version does 4-byte comparison at a time when n >=4, > then fall back to 1-byte for the rest. I don't know if it's faster > than a plain always 1-byte comparison though. There's also the hand > written assembly version that compares n from 1..16, not exactly

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-10 Thread Duy Nguyen
On Sun, Mar 10, 2013 at 7:11 PM, Antoine Pelisse wrote: >>> By the way, if we know the length of the string, we could use memcmp. >>> This one is allowed to compare 4-bytes at a time (he doesn't care >>> about end of string). This is true because the value of the length >>> parameter is no longer

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-10 Thread Antoine Pelisse
>> By the way, if we know the length of the string, we could use memcmp. >> This one is allowed to compare 4-bytes at a time (he doesn't care >> about end of string). This is true because the value of the length >> parameter is no longer "at most". > > We still need to worry about access violation

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-10 Thread Duy Nguyen
On Sun, Mar 10, 2013 at 6:54 PM, Antoine Pelisse wrote: > On Sun, Mar 10, 2013 at 12:43 PM, Antoine Pelisse wrote: >> On Sun, Mar 10, 2013 at 11:38 AM, Duy Nguyen wrote: >>> glibc's C strncmp version does 4-byte comparison at a time when n >=4, >>> then fall back to 1-byte for the rest. >> >> Lo

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-10 Thread Antoine Pelisse
On Sun, Mar 10, 2013 at 12:43 PM, Antoine Pelisse wrote: > On Sun, Mar 10, 2013 at 11:38 AM, Duy Nguyen wrote: >> glibc's C strncmp version does 4-byte comparison at a time when n >=4, >> then fall back to 1-byte for the rest. > > Looking at this > (http://fossies.org/dox/glibc-2.17/strncmp_8c_so

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-10 Thread Antoine Pelisse
On Sun, Mar 10, 2013 at 11:38 AM, Duy Nguyen wrote: > glibc's C strncmp version does 4-byte comparison at a time when n >=4, > then fall back to 1-byte for the rest. Looking at this (http://fossies.org/dox/glibc-2.17/strncmp_8c_source.html), it's not exactly true. It would rather be while (n >=

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-10 Thread Duy Nguyen
On Sun, Mar 10, 2013 at 2:34 PM, Junio C Hamano wrote: > Nguyễn Thái Ngọc Duy writes: > >> strncmp is provided length information which could be taken advantage >> by the underlying implementation. > > I may be missing something fundamental, but I somehow find the above > does not make any sense

Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp

2013-03-09 Thread Junio C Hamano
Nguyễn Thái Ngọc Duy writes: > strncmp is provided length information which could be taken advantage > by the underlying implementation. I may be missing something fundamental, but I somehow find the above does not make any sense. strcmp(a, b) has to pay attention to NUL in these strings and s