diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-01-26 18:48:36 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-01-26 10:44:10 -0800 |
commit | 24072c0256a520408575416fe8706667b576ff99 (patch) | |
tree | 1155e3fcc4cd65d214fc406e1858f95f283d12eb /grep.c | |
parent | e3f67d30b20e49d8fc3eefe819808cba7998b060 (diff) | |
download | git-24072c0256a520408575416fe8706667b576ff99.tar.gz |
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 <benny.kra@googlemail.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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) |