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

2013-03-12 Thread Junio C Hamano
Duy Nguyen pclo...@gmail.com 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

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 gits...@pobox.com 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

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 gits...@pobox.com wrote: Nguyễn Thái Ngọc Duy pclo...@gmail.com 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

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 pclo...@gmail.com 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

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 apeli...@gmail.com wrote: On Sun, Mar 10, 2013 at 11:38 AM, Duy Nguyen pclo...@gmail.com 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

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 apeli...@gmail.com wrote: On Sun, Mar 10, 2013 at 12:43 PM, Antoine Pelisse apeli...@gmail.com wrote: On Sun, Mar 10, 2013 at 11:38 AM, Duy Nguyen pclo...@gmail.com wrote: glibc's C strncmp version does 4-byte comparison at a time when n =4,

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 after NUL

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 apeli...@gmail.com 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

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

2013-03-09 Thread Nguyễn Thái Ngọc Duy
strncmp is provided length information which could be taken advantage by the underlying implementation. Even better, we need to check if the lengths are equal before calling strncmp, eliminating a bit of strncmp calls. before after user0m0.548s0m0.516s user0m0.549s

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 pclo...@gmail.com 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