Skip to content

Commit e2b1542

Browse files
rscharfegitster
authored andcommitted
grep: use grep_not_expr() in compile_pattern_not()
Move the definition of grep_not_expr() up and use this function in compile_pattern_not() to simplify the code and reduce duplication. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9dbf00b commit e2b1542

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

grep.c

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

598+
static struct grep_expr *grep_not_expr(struct grep_expr *expr)
599+
{
600+
struct grep_expr *z = xcalloc(1, sizeof(*z));
601+
z->node = GREP_NODE_NOT;
602+
z->u.unary = expr;
603+
return z;
604+
}
605+
598606
static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
599607
{
600608
struct grep_expr *z = xcalloc(1, sizeof(*z));
@@ -647,12 +655,10 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
647655
if (!p->next)
648656
die("--not not followed by pattern expression");
649657
*list = p->next;
650-
CALLOC_ARRAY(x, 1);
651-
x->node = GREP_NODE_NOT;
652-
x->u.unary = compile_pattern_not(list);
653-
if (!x->u.unary)
658+
x = compile_pattern_not(list);
659+
if (!x)
654660
die("--not followed by non pattern expression");
655-
return x;
661+
return grep_not_expr(x);
656662
default:
657663
return compile_pattern_atom(list);
658664
}
@@ -704,14 +710,6 @@ static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
704710
return compile_pattern_or(list);
705711
}
706712

707-
static struct grep_expr *grep_not_expr(struct grep_expr *expr)
708-
{
709-
struct grep_expr *z = xcalloc(1, sizeof(*z));
710-
z->node = GREP_NODE_NOT;
711-
z->u.unary = expr;
712-
return z;
713-
}
714-
715713
static struct grep_expr *grep_true_expr(void)
716714
{
717715
struct grep_expr *z = xcalloc(1, sizeof(*z));

0 commit comments

Comments
 (0)