Skip to content

Commit 9dbf00b

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e83ba64 commit 9dbf00b

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

grep.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,15 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
595595
}
596596
}
597597

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+
598607
static struct grep_expr *compile_pattern_or(struct grep_pat **);
599608
static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
600609
{
@@ -677,19 +686,15 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
677686
static struct grep_expr *compile_pattern_or(struct grep_pat **list)
678687
{
679688
struct grep_pat *p;
680-
struct grep_expr *x, *y, *z;
689+
struct grep_expr *x, *y;
681690

682691
x = compile_pattern_and(list);
683692
p = *list;
684693
if (x && p && p->token != GREP_CLOSE_PAREN) {
685694
y = compile_pattern_or(list);
686695
if (!y)
687696
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);
693698
}
694699
return x;
695700
}
@@ -714,15 +719,6 @@ static struct grep_expr *grep_true_expr(void)
714719
return z;
715720
}
716721

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-
726722
static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
727723
{
728724
struct grep_pat *p;

0 commit comments

Comments
 (0)