grep: use grep_or_expr() in compile_pattern_or()
Move the definition of grep_or_expr() up and use this function in compile_pattern_or() to reduce code duplication. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jan 6, 2022 at 10:51 UTC
9dbf00ba785e2cf950fadb2c20e81422ebb1a4d5
1 file changed
+11
-15
grep.c
+11
-15
@@ -595,6 +595,15 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
595
}
596
}
597
598
+static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
599
+{
600
+ struct grep_expr *z = xcalloc(1, sizeof(*z));
601
+ z->node = GREP_NODE_OR;
602
+ z->u.binary.left = left;
603
+ z->u.binary.right = right;
604
+ return z;
605
+}
606
+
607
static struct grep_expr *compile_pattern_or(struct grep_pat **);
608
static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
609
{
@@ -677,7 +686,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
686
static struct grep_expr *compile_pattern_or(struct grep_pat **list)
687
{
688
struct grep_pat *p;
680
- struct grep_expr *x, *y, *z;
689
+ struct grep_expr *x, *y;
690
691
x = compile_pattern_and(list);
692
p = *list;
@@ -685,11 +694,7 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)
694
y = compile_pattern_or(list);
695
if (!y)
696
die("not a pattern expression %s", p->pattern);
688
- CALLOC_ARRAY(z, 1);
689
- z->node = GREP_NODE_OR;
690
- z->u.binary.left = x;
691
- z->u.binary.right = y;
692
- return z;
697
+ return grep_or_expr(x, y);
698
}
699
return x;
700
}
@@ -714,15 +719,6 @@ static struct grep_expr *grep_true_expr(void)
719
return z;
720
}
721
717
-static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
718
-{
719
- struct grep_expr *z = xcalloc(1, sizeof(*z));
720
- z->node = GREP_NODE_OR;
721
- z->u.binary.left = left;
722
- z->u.binary.right = right;
723
- return z;
724
-}
725
-
722
static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
723
{
724
struct grep_pat *p;