Re: [PATCH/RFC v3 6/8] Add case insensitivity support when using git ls-files
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Oct 4, 2010, 07:49 UTC
- Message-ID
- <20101004074916.GK24884@burratino>
- In-Reply-To
- <201010032019.09244.j6t@kdbg.org>
Johannes Sixt wrote:
> On Sonntag, 3. Oktober 2010, Thomas Adam wrote:
Show 10 quoted lines
>> It's a real shame about the code duplication here. Can we not avoid >> it just by doing: >> >> unsigned char c1 = (ignore_case) ? tolower(*match) : *match; >> unisgned char c2 = (ignore_case) ? tolower(*name) : *name; >> >> I appreciate that to some it might look like perl golf, but... > > It has been discussed, and IIRC, the concensus was to keep the code > duplication because this is an inner loop.
Did anyone time it? If it really is not dwarfed by other computation, then how about (warning: ugly!)
static inline int step(unsigned char c1, unsigned char c2,
const char **match, const char **name, int *namelen)
{
if (c1 == '\0' || is_glob_special(c1))
return 1; /* break */
if (c1 != c2)
return 0; /* found mismatch! */
(*match)++;
(*name)++;
(*namelen)--;
return 2; /* continue */
}
...int r = 1;
if (!ignore_case) {
while ((r = step(*match, *name, &match, &name, &namelen)) == 2)
; /* matches so far */
} else {
while ((r = step(tolower(*match), tolower(*name),
&match, &name, &namelen)) == 2)
; /* matches so far */
}
if (!r) /* found mismatch! */
return 0;