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:18 UTC
- Message-ID
- <CAPig+cSrt3FE081a=7in_h2njCbhPfaSHm+S+e8-DLuvP7Ga0w@mail.gmail.com>
- In-Reply-To
- <1453982183-24124-5-git-send-email-pclouds@gmail.com>
On Thu, Jan 28, 2016 at 6:56 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 23 quoted lines
> 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.
> p->fixed = 1;
> else if (opt->fixed) {
> p->fixed = 1;