All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: git@vger.kernel.org, l.s.r@web.de
Subject: Re: [PATCH 2/2] grep: use grep_and_expr() in compile_pattern_and()
Date: Thu, 06 Jan 2022 14:14:47 -0800	[thread overview]
Message-ID: <xmqqlezsbjfs.fsf@gitster.g> (raw)
In-Reply-To: <71bd2d1bcc6486f2e21c649708d3f4fa67dc162c.1641498525.git.me@ttaylorr.com> (Taylor Blau's message of "Thu, 6 Jan 2022 14:50:15 -0500")

Taylor Blau <me@ttaylorr.com> writes:

> In a similar spirit as a previous commit, use the new `grep_and_expr()`
> to construct the AND node in `compile_pattern_and()`.
>
> Unlike the aforementioned previous commit, this is not about code
> duplication, since this is the only spot in grep.c where an AND node is
> constructed. Rather, this is about visual consistency with the other
> `compile_pattern_xyz()` functions.
>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
>  grep.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/grep.c b/grep.c
> index d772fe6cc5..ab4fdacaed 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -619,6 +619,11 @@ static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *
>  	return grep_binexp(GREP_NODE_OR, left, right);
>  }
>  
> +static struct grep_expr *grep_and_expr(struct grep_expr *left, struct grep_expr *right)
> +{
> +	return grep_binexp(GREP_NODE_AND, left, right);
> +}
> +
>  static struct grep_expr *compile_pattern_or(struct grep_pat **);
>  static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
>  {
> @@ -687,11 +692,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
>  		y = compile_pattern_and(list);
>  		if (!y)
>  			die("--and not followed by pattern expression");
> -		CALLOC_ARRAY(z, 1);
> -		z->node = GREP_NODE_AND;
> -		z->u.binary.left = x;
> -		z->u.binary.right = y;
> -		return z;
> +		return grep_and_expr(x, y);

You'd need to remove 'z' from the function to avoid getting yelled
at by your compiler for unused variable.


  reply	other threads:[~2022-01-06 22:14 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   ` [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 [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqlezsbjfs.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=me@ttaylorr.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.