Re: [PATCH v3 05/13] match_{base,path}name: replace strncmp_icase with memequal_icase
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Mar 13, 2013, 01:14 UTC
- Message-ID
- <CACsJy8Du7XMPWa032kSp0-z6j2ggOYHAQ0xadt=-XCATM5rPRw@mail.gmail.com>
- In-Reply-To
- <1363093500-16796-6-git-send-email-pclouds@gmail.com>
On Tue, Mar 12, 2013 at 8:04 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 22 quoted lines
> +static inline int memequal_icase(const char *a, const char *b, int n)
> +{
> + if (!memcmp(a, b, n))
> + return 1;
> +
> + if (!ignore_case)
> + return 0;
> +
> + /*
> + * This assumes that ASCII is used in most repositories. We
> + * try the ascii-only version first (i.e. Git's
> + * toupper). Failing that, fall back to normal strncasecmp.
> + */
> + while (n && toupper(*a) == toupper(*b)) {
> + a++;
> + b++;
> + n--;
> + }
> + if (!n)
> + return 1;
> + return !strncasecmp(a, b, n);
> +}Note, the ignore_case == 1 codepath was not tested and measured. I suspect that strncasecmp may be more complex to support locales and the "LANG=C" version should suffice in most case. But it's just guesses at this moment.
-- Duy