git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Beller <sbeller@google.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Jens.Lehmann@web.de, peff@peff.net,
	sunshine@sunshineco.com, jrnieder@gmail.com,
	Stefan Beller <sbeller@google.com>
Subject: [PATCH] strbuf_write: omit system call when length is zero
Date: Thu, 25 Feb 2016 14:34:38 -0800	[thread overview]
Message-ID: <1456439678-5433-1-git-send-email-sbeller@google.com> (raw)

In case the length of the buffer is zero, we do not need to call the
fwrite system call as a performance improvement.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

 This applies on top of v17 for origin/sb/submodule-parallel-update.
 
 In case there are other reasons for origin/sb/submodule-parallel-update
 to need a reroll I'll squash it in. But as this is a pure performance
 optimization in a case we are not running into with that series and that
 series is clashing with Davids refs backend series, I figure we may not
 want to have a reroll for this fix alone.
 
 Thanks,
 Stefan
  

 strbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/strbuf.c b/strbuf.c
index 71345cd..5f6da82 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -397,7 +397,7 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
 
 ssize_t strbuf_write(struct strbuf *sb, FILE *f)
 {
-	return fwrite(sb->buf, 1, sb->len, f);
+	return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
 }
 
 
-- 
2.7.2.374.ga5f0819.dirty

             reply	other threads:[~2016-02-25 22:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 22:34 Stefan Beller [this message]
2016-02-25 23:04 ` [PATCH] strbuf_write: omit system call when length is zero Junio C Hamano
2016-02-26  0:47 ` Duy Nguyen
2016-02-26  1:40   ` Junio C Hamano
2016-02-26 17:09     ` Stefan Beller

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=1456439678-5433-1-git-send-email-sbeller@google.com \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.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).