Skip to content

Commit 0a6adc2

Browse files
ttaylorrgitster
authored andcommitted
grep: use grep_and_expr() in compile_pattern_and()
In a similar spirit as a previous commit, use the new `grep_and_expr()` to construct the AND node in `compile_pattern_and()`. Unlike the aforementioned previous commit, this is not about code duplication, since this is the only spot in grep.c where an AND node is constructed. Rather, this is about visual consistency with the other `compile_pattern_xyz()` functions. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2d2759 commit 0a6adc2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

grep.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *
619619
return grep_binexp(GREP_NODE_OR, left, right);
620620
}
621621

622+
static struct grep_expr *grep_and_expr(struct grep_expr *left, struct grep_expr *right)
623+
{
624+
return grep_binexp(GREP_NODE_AND, left, right);
625+
}
626+
622627
static struct grep_expr *compile_pattern_or(struct grep_pat **);
623628
static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
624629
{
@@ -674,7 +679,7 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
674679
static struct grep_expr *compile_pattern_and(struct grep_pat **list)
675680
{
676681
struct grep_pat *p;
677-
struct grep_expr *x, *y, *z;
682+
struct grep_expr *x, *y;
678683

679684
x = compile_pattern_not(list);
680685
p = *list;
@@ -687,11 +692,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
687692
y = compile_pattern_and(list);
688693
if (!y)
689694
die("--and not followed by pattern expression");
690-
CALLOC_ARRAY(z, 1);
691-
z->node = GREP_NODE_AND;
692-
z->u.binary.left = x;
693-
z->u.binary.right = y;
694-
return z;
695+
return grep_and_expr(x, y);
695696
}
696697
return x;
697698
}

0 commit comments

Comments
 (0)