git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] grep: use grep_or_expr() in compile_pattern_or()
@ 2022-01-06  9:51 René Scharfe
  2022-01-06  9:54 ` [PATCH 2/2] grep: use grep_not_expr() in compile_pattern_not() René Scharfe
  2022-01-06 19:50 ` [PATCH 0/2] grep: introduce and use grep_and_expr() Taylor Blau
  0 siblings, 2 replies; 13+ messages in thread
From: René Scharfe @ 2022-01-06  9:51 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

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 <l.s.r@web.de>
---
 grep.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/grep.c b/grep.c
index 47c75ab7fb..f1bbe80ccb 100644
--- a/grep.c
+++ b/grep.c
@@ -595,6 +595,15 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
 	}
 }

+static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
+{
+	struct grep_expr *z = xcalloc(1, sizeof(*z));
+	z->node = GREP_NODE_OR;
+	z->u.binary.left = left;
+	z->u.binary.right = right;
+	return z;
+}
+
 static struct grep_expr *compile_pattern_or(struct grep_pat **);
 static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
 {
@@ -677,7 +686,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
 static struct grep_expr *compile_pattern_or(struct grep_pat **list)
 {
 	struct grep_pat *p;
-	struct grep_expr *x, *y, *z;
+	struct grep_expr *x, *y;

 	x = compile_pattern_and(list);
 	p = *list;
@@ -685,11 +694,7 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)
 		y = compile_pattern_or(list);
 		if (!y)
 			die("not a pattern expression %s", p->pattern);
-		CALLOC_ARRAY(z, 1);
-		z->node = GREP_NODE_OR;
-		z->u.binary.left = x;
-		z->u.binary.right = y;
-		return z;
+		return grep_or_expr(x, y);
 	}
 	return x;
 }
@@ -714,15 +719,6 @@ static struct grep_expr *grep_true_expr(void)
 	return z;
 }

-static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
-{
-	struct grep_expr *z = xcalloc(1, sizeof(*z));
-	z->node = GREP_NODE_OR;
-	z->u.binary.left = left;
-	z->u.binary.right = right;
-	return z;
-}
-
 static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
 {
 	struct grep_pat *p;
--
2.34.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-01-07 19:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06  9:51 [PATCH 1/2] grep: use grep_or_expr() in compile_pattern_or() René Scharfe
2022-01-06  9:54 ` [PATCH 2/2] grep: use grep_not_expr() in compile_pattern_not() René Scharfe
2022-01-06 19:50 ` [PATCH 0/2] grep: introduce and use grep_and_expr() Taylor Blau
2022-01-06 19:50   ` [PATCH 1/2] grep: extract grep_binexp() from grep_or_expr() Taylor Blau
2022-01-06 19:50   ` [PATCH 2/2] grep: use grep_and_expr() in compile_pattern_and() Taylor Blau
2022-01-06 22:14     ` Junio C Hamano
2022-01-06 22:43       ` Taylor Blau
2022-01-06 22:42   ` [PATCH v2 0/2] grep: introduce and use grep_and_expr() Taylor Blau
2022-01-06 22:42     ` [PATCH v2 1/2] grep: extract grep_binexp() from grep_or_expr() Taylor Blau
2022-01-06 22:42     ` [PATCH v2 2/2] grep: use grep_and_expr() in compile_pattern_and() Taylor Blau
2022-01-07 12:57   ` [PATCH 0/2] grep: introduce and use grep_and_expr() René Scharfe
2022-01-07 19:33     ` Taylor Blau
2022-01-07 19:54       ` René Scharfe

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).