From: Duy Nguyen Date: Wed, 13 Mar 2013 01:14:14 GMT Subject: Re: [PATCH v3 05/13] match_{base,path}name: replace strncmp_icase with memequal_icase Message-ID: 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 wrote: > +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