From: Benjamin Kramer Date: Tue, 26 Jan 2010 17:48:36 +0000 (+0100) Subject: grep: use REG_STARTEND (if available) to speed up regexec X-Git-Tag: v1.7.0-rc1~32 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=24072c0256a520408575416fe8706667b576ff99;p=git.git grep: use REG_STARTEND (if available) to speed up regexec BSD and glibc have an extension to regexec which takes a buffer + length pair instead of a NUL-terminated string. Since we already have the length computed this can save us a strlen call inside regexec. Signed-off-by: Benjamin Kramer Acked-by: Linus Torvalds Signed-off-by: Junio C Hamano --- diff --git a/grep.c b/grep.c index 8e1f7de77..452c2cbae 100644 --- a/grep.c +++ b/grep.c @@ -640,8 +640,15 @@ static int look_ahead(struct grep_opt *opt, if (p->fixed) hit = !fixmatch(p->pattern, bol, p->ignore_case, &m); - else + else { +#ifdef REG_STARTEND + m.rm_so = 0; + m.rm_eo = *left_p; + hit = !regexec(&p->regexp, bol, 1, &m, REG_STARTEND); +#else hit = !regexec(&p->regexp, bol, 1, &m, 0); +#endif + } if (!hit || m.rm_so < 0 || m.rm_eo < 0) continue; if (earliest < 0 || m.rm_so < earliest)