From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Git Mailing List <git@vger.kernel.org>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Thiago Alves" <thiago.salves@gmail.com>
Subject: [PATCH 1/5] grep: micro-optimize hit collection for AND nodes
Date: Sat, 07 Mar 2009 13:27:15 +0100 [thread overview]
Message-ID: <1236428835.6486.43.camel@ubuntu.ubuntu-domain> (raw)
In-Reply-To: <1236428699.6486.41.camel@ubuntu.ubuntu-domain>
In addition to returning if an expression matches a line,
match_expr_eval() updates the expression's hit flag if the parameter
collect_hits is set. It never sets collect_hits for children of AND
nodes, though, so their hit flag will never be updated. Because of
that we can return early if the first child didn't match, no matter
if collect_hits is set or not.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
grep.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/grep.c b/grep.c
index 062b2b6..db341b6 100644
--- a/grep.c
+++ b/grep.c
@@ -394,13 +394,9 @@ static int match_expr_eval(struct grep_opt *o,
h = !match_expr_eval(o, x->u.unary, bol, eol, ctx, 0);
break;
case GREP_NODE_AND:
- if (!collect_hits)
- return (match_expr_eval(o, x->u.binary.left,
- bol, eol, ctx, 0) &&
- match_expr_eval(o, x->u.binary.right,
- bol, eol, ctx, 0));
- h = match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0);
- h &= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
+ if (!match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0))
+ return 0;
+ h = match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
break;
case GREP_NODE_OR:
if (!collect_hits)
--
1.6.2
next prev parent reply other threads:[~2009-03-07 12:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-07 12:24 [PATCH 0/5] grep: color search patterns René Scharfe
2009-03-07 12:27 ` René Scharfe [this message]
2009-03-07 12:28 ` [PATCH 2/5] grep: remove grep_opt argument from match_expr_eval() René Scharfe
2009-03-07 12:30 ` [PATCH 3/5] grep: add pmatch and eflags arguments to match_one_pattern() René Scharfe
2009-03-07 12:32 ` [PATCH 4/5] grep: color patterns in output René Scharfe
2009-03-07 12:34 ` [PATCH 5/5] grep: add support for coloring with external greps René Scharfe
2009-03-10 6:01 ` [PATCH 0/5] grep: color search patterns Nguyen Thai Ngoc Duy
2009-03-10 16:38 ` René Scharfe
2009-03-16 2:20 ` [PATCH] grep: prefer builtin over external one when coloring results pclouds
2009-03-16 17:31 ` 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=1236428835.6486.43.camel@ubuntu.ubuntu-domain \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=thiago.salves@gmail.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 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 NNTP newsgroup(s).