Skip to content

Commit 885d211

Browse files
committed
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 <gitster@pobox.com>
1 parent bbc09c2 commit 885d211

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

grep.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,14 @@ void append_grep_pattern(struct grep_opt *opt, const char *pat,
2929
p->next = NULL;
3030
}
3131

32-
static int is_fixed(const char *s)
33-
{
34-
while (*s && !is_regex_special(*s))
35-
s++;
36-
return !*s;
37-
}
38-
3932
static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
4033
{
4134
int err;
4235

4336
p->word_regexp = opt->word_regexp;
4437
p->ignore_case = opt->ignore_case;
4538

46-
if (opt->fixed || is_fixed(p->pattern))
39+
if (opt->fixed)
4740
p->fixed = 1;
4841
if (opt->regflags & REG_ICASE)
4942
p->fixed = 0;

0 commit comments

Comments
 (0)