From: Rasmus Villemoes <rv@rasmusvillemoes.dk>
To: git@vger.kernel.org
Cc: Rasmus Villemoes <rv@rasmusvillemoes.dk>
Subject: [PATCH 2/3] grep: simplify grep_oid and grep_file
Date: Thu, 15 Feb 2018 22:56:14 +0100 [thread overview]
Message-ID: <20180215215615.21208-3-rv@rasmusvillemoes.dk> (raw)
In-Reply-To: <20180215215615.21208-1-rv@rasmusvillemoes.dk>
In the NO_PTHREADS or !num_threads case, this doesn't change
anything. In the threaded case, note that grep_source_init duplicates
its third argument, so there is no need to keep [path]buf.buf alive
across the call of add_work().
Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
builtin/grep.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 4a4f15172..593f48d59 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -326,18 +326,17 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
}
grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
+ strbuf_release(&pathbuf);
#ifndef NO_PTHREADS
if (num_threads) {
add_work(opt, &gs);
- strbuf_release(&pathbuf);
return 0;
} else
#endif
{
int hit;
- strbuf_release(&pathbuf);
hit = grep_source(opt, &gs);
grep_source_clear(&gs);
@@ -356,18 +355,17 @@ static int grep_file(struct grep_opt *opt, const char *filename)
strbuf_addstr(&buf, filename);
grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
+ strbuf_release(&buf);
#ifndef NO_PTHREADS
if (num_threads) {
add_work(opt, &gs);
- strbuf_release(&buf);
return 0;
} else
#endif
{
int hit;
- strbuf_release(&buf);
hit = grep_source(opt, &gs);
grep_source_clear(&gs);
--
2.15.1
next prev parent reply other threads:[~2018-02-15 21:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 21:56 [PATCH 0/3] a few grep patches Rasmus Villemoes
2018-02-15 21:56 ` [PATCH 1/3] grep: move grep_source_init outside critical section Rasmus Villemoes
2018-02-15 22:17 ` Jeff King
2018-02-16 19:24 ` Junio C Hamano
2018-02-15 21:56 ` Rasmus Villemoes [this message]
2018-02-15 21:56 ` [PATCH 3/3] grep: avoid one strdup() per file Rasmus Villemoes
2018-02-15 22:18 ` Jeff King
2018-02-15 22:02 ` [PATCH 0/3] a few grep patches Brandon Williams
2018-02-23 14:47 ` [PATCH v2 0/2] two small " Rasmus Villemoes
2018-02-23 14:47 ` [PATCH v2 1/2] grep: move grep_source_init outside critical section Rasmus Villemoes
2018-02-23 14:47 ` [PATCH v2 2/2] grep: simplify grep_oid and grep_file Rasmus Villemoes
2018-02-23 18:01 ` [PATCH v2 0/2] two small grep patches Jeff King
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=20180215215615.21208-3-rv@rasmusvillemoes.dk \
--to=rv@rasmusvillemoes.dk \
--cc=git@vger.kernel.org \
/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).