Skip to content

Commit f2d2759

Browse files
ttaylorrgitster
authored andcommitted
grep: extract grep_binexp() from grep_or_expr()
When constructing an OR node, the grep.c code uses `grep_or_expr()` to make a node, assign its kind, and set its left and right children. The same is not done for AND nodes. Prepare to introduce a new `grep_and_expr()` function which will share code with the existing implementation of `grep_or_expr()` by introducing a new function which compiles either kind of binary expression, and reimplement `grep_or_expr()` in terms of it. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e2b1542 commit f2d2759

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

grep.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,22 @@ static struct grep_expr *grep_not_expr(struct grep_expr *expr)
603603
return z;
604604
}
605605

606-
static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
606+
static struct grep_expr *grep_binexp(enum grep_expr_node kind,
607+
struct grep_expr *left,
608+
struct grep_expr *right)
607609
{
608610
struct grep_expr *z = xcalloc(1, sizeof(*z));
609-
z->node = GREP_NODE_OR;
611+
z->node = kind;
610612
z->u.binary.left = left;
611613
z->u.binary.right = right;
612614
return z;
613615
}
614616

617+
static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
618+
{
619+
return grep_binexp(GREP_NODE_OR, left, right);
620+
}
621+
615622
static struct grep_expr *compile_pattern_or(struct grep_pat **);
616623
static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
617624
{

0 commit comments

Comments
 (0)