From: Taylor Blau <me@ttaylorr.com>
To: git@vger.kernel.org
Cc: l.s.r@web.de, gitster@pobox.com
Subject: [PATCH 1/2] grep: extract grep_binexp() from grep_or_expr()
Date: Thu, 6 Jan 2022 14:50:12 -0500 [thread overview]
Message-ID: <dae476d1bd14608358b6c103e2b5dda76d294687.1641498525.git.me@ttaylorr.com> (raw)
In-Reply-To: <cover.1641498525.git.me@ttaylorr.com>
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 <me@ttaylorr.com>
---
grep.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/grep.c b/grep.c
index bdbd06d437..d772fe6cc5 100644
--- a/grep.c
+++ b/grep.c
@@ -603,15 +603,22 @@ static struct grep_expr *grep_not_expr(struct grep_expr *expr)
return z;
}
-static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
+static struct grep_expr *grep_binexp(enum grep_expr_node kind,
+ struct grep_expr *left,
+ struct grep_expr *right)
{
struct grep_expr *z = xcalloc(1, sizeof(*z));
- z->node = GREP_NODE_OR;
+ z->node = kind;
z->u.binary.left = left;
z->u.binary.right = right;
return z;
}
+static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
+{
+ return grep_binexp(GREP_NODE_OR, left, right);
+}
+
static struct grep_expr *compile_pattern_or(struct grep_pat **);
static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
{
--
2.34.1.455.gd6eb6fd089
next prev parent reply other threads:[~2022-01-06 19:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Taylor Blau [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dae476d1bd14608358b6c103e2b5dda76d294687.1641498525.git.me@ttaylorr.com \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).