Skip to content

Commit

Permalink
grep: rip out pessimization to use fixmatch()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jan 13, 2010
1 parent bbc09c2 commit 885d211
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@ 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;

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;
Expand Down

0 comments on commit 885d211

Please sign in to comment.