Re: [PATCH v2 3/6] match_basename: use strncmp instead of strcmp
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 12, 2013, 20:59 UTC
- Message-ID
- <7v7glc72rn.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <CACsJy8A_4SqLu5L6P0PJ78Lwy12fjL7T2p-KbVEVLJmKNqhyRw@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
Show 5 quoted lines
> 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 sure > how this version works yet.
It sounds to me more like "a very popular implementation of strcmp/strncmp pair found to have more optimized strncmp than strcmp". While that may be a good reason to justify this patch, I do not think it justifies this:
>> 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 boundary.