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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jan 6, 2022 at 10:54 UTC
e2b154277addad0a70b23d03c9156ac8e08c4a82
1 file changed
+11
-13
grep.c
+11
-13
@@ -595,6 +595,14 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
595
}
596
}
597
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
+
606
static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
607
{
608
struct grep_expr *z = xcalloc(1, sizeof(*z));
@@ -647,12 +655,10 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
655
if (!p->next)
656
die("--not not followed by pattern expression");
657
*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)
660
die("--not followed by non pattern expression");
655
- return x;
661
+ return grep_not_expr(x);
662
default:
663
return compile_pattern_atom(list);
664
}
@@ -704,14 +710,6 @@ static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
710
return compile_pattern_or(list);
711
}
712
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
-
713
static struct grep_expr *grep_true_expr(void)
714
{
715
struct grep_expr *z = xcalloc(1, sizeof(*z));