Re: [PATCH v5 04/10] grep/icase: avoid kwsset on literal non-ascii strings
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jan 29, 2016, 06:41 UTC
- Message-ID
- <CAPig+cSgMM2zjdqbtw0HZ1gmLoiBA5h_cD_oMTDA_23unThEFA@mail.gmail.com>
- In-Reply-To
- <CAPig+cSrt3FE081a=7in_h2njCbhPfaSHm+S+e8-DLuvP7Ga0w@mail.gmail.com>
On Fri, Jan 29, 2016 at 1:18 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 28 quoted lines
> On Thu, Jan 28, 2016 at 6:56 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> When we detect the pattern is just a literal string, we avoid heavy
>> regex engine and use fast substring search implemented in kwsset.c.
>> But kws uses git-ctype which is locale-independent so it does not know
>> how to fold case properly outside ascii range. Let regcomp or pcre
>> take care of this case instead. Slower, but accurate.
>>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>> diff --git a/grep.c b/grep.c
>> @@ -398,12 +399,16 @@ static int is_fixed(const char *s, size_t len)
>> static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
>> {
>> + int icase_non_ascii;
>> int err;
>>
>> p->word_regexp = opt->word_regexp;
>> p->ignore_case = opt->ignore_case;
>> + icase_non_ascii =
>> + (opt->regflags & REG_ICASE || p->ignore_case) &&
>> + has_non_ascii(p->pattern);
>>
>> - if (is_fixed(p->pattern, p->patternlen))
>> + if (!icase_non_ascii && is_fixed(p->pattern, p->patternlen))
>
> These double negatives (!non_ascii) here and in patch 5/10 are
> difficult to grok. I wonder if a different name, such as
> icase_ascii_only would help.By the way, this is such a minor issue, and since there are only two cases (in patches 4/10 and 5/10), it's not worth worrying about, and certainly not worth a reroll.