]> rtime.felk.cvut.cz Git - git.git/blobdiff - grep.c
grep: use REG_STARTEND (if available) to speed up regexec
[git.git] / grep.c
diff --git a/grep.c b/grep.c
index 8e1f7de7717da95e8954491f5205547f2091aa35..452c2cbae4c4b706c867574c437490cdf7ac9bd5 100644 (file)
--- 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)