Code

grep: micro-optimize hit collection for AND nodes
[git.git] / grep.c
diff --git a/grep.c b/grep.c
index 6485760ff30e0575ee13b43fc8c7fb8e2e291346..db341b6797ccb5e44796ff1556437677f595a913 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -28,15 +28,9 @@ void append_grep_pattern(struct grep_opt *opt, const char *pat,
        p->next = NULL;
 }
 
-static int isregexspecial(int c)
-{
-       return isspecial(c) || c == '$' || c == '(' || c == ')' || c == '+' ||
-                              c == '.' || c == '^' || c == '{' || c == '|';
-}
-
 static int is_fixed(const char *s)
 {
-       while (!isregexspecial(*s))
+       while (*s && !is_regex_special(*s))
                s++;
        return !*s;
 }
@@ -400,13 +394,9 @@ static int match_expr_eval(struct grep_opt *o,
                h = !match_expr_eval(o, x->u.unary, bol, eol, ctx, 0);
                break;
        case GREP_NODE_AND:
-               if (!collect_hits)
-                       return (match_expr_eval(o, x->u.binary.left,
-                                               bol, eol, ctx, 0) &&
-                               match_expr_eval(o, x->u.binary.right,
-                                               bol, eol, ctx, 0));
-               h = match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0);
-               h &= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
+               if (!match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0))
+                       return 0;
+               h = match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
                break;
        case GREP_NODE_OR:
                if (!collect_hits)