Thread (44 messages) 44 messages, 3 authors, 2016-06-15

Re: [PATCH v5 04/10] grep/icase: avoid kwsset on literal non-ascii strings

flat view

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:08:01

On Thu, Jan 28, 2016 at 6:56 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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 <redacted>
---
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;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help