From: Junio C Hamano Date: Wed, 13 Jan 2010 03:21:46 +0000 (-0800) Subject: grep: rip out pessimization to use fixmatch() X-Git-Tag: v1.7.0-rc0~64^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=885d211e714b3787cd059e347694f9b24e1db1f3;p=git.git grep: rip out pessimization to use fixmatch() Even when running without the -F (--fixed-strings) option, we checked the pattern and used fixmatch() codepath when it does not contain any regex magic. Finding fixed strings with strstr() surely must be faster than running the regular expression crud. Not so. It turns out that on some libc implementations, using the regcomp()/regexec() pair is a lot faster than running strstr() and strcasestr() the fixmatch() codepath uses. Drop the optimization and use the fixmatch() codepath only when the user explicitly asked for it with the -F option. Signed-off-by: Junio C Hamano --- diff --git a/grep.c b/grep.c index 62723da13..8e1f7de77 100644 --- a/grep.c +++ b/grep.c @@ -29,13 +29,6 @@ void append_grep_pattern(struct grep_opt *opt, const char *pat, p->next = NULL; } -static int is_fixed(const char *s) -{ - while (*s && !is_regex_special(*s)) - s++; - return !*s; -} - static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) { int err; @@ -43,7 +36,7 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) p->word_regexp = opt->word_regexp; p->ignore_case = opt->ignore_case; - if (opt->fixed || is_fixed(p->pattern)) + if (opt->fixed) p->fixed = 1; if (opt->regflags & REG_ICASE) p->fixed = 0;