public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Duy Nguyen <pclouds@gmail•com>
Cc: Stefan Beller <sbeller@google•com>,
	Git Mailing List <git@vger•kernel.org>,
	Jens Lehmann <Jens.Lehmann@web•de>, Jeff King <peff@peff•net>,
	Eric Sunshine <sunshine@sunshineco•com>,
	Jonathan Nieder <jrnieder@gmail•com>
Subject: Re: [PATCH] strbuf_write: omit system call when length is zero
Date: Thu, 25 Feb 2016 17:40:48 -0800	[thread overview]
Message-ID: <xmqqy4a8l04f.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <CACsJy8DgjmdX681fRwB-JajPBRN+cNy=jFwEDW6D-dXhNi=_6g@mail.gmail.com> (Duy Nguyen's message of "Fri, 26 Feb 2016 07:47:44 +0700")

Duy Nguyen <pclouds@gmail•com> writes:

> On Fri, Feb 26, 2016 at 5:34 AM, Stefan Beller <sbeller@google•com> wrote:
>> In case the length of the buffer is zero, we do not need to call the
>> fwrite system call as a performance improvement.
>
> fwrite is a libc call, not system call. Are you sure it always calls
> write() (assuming buffering is off)?

I do not think so, but I suspect that the patch misstates its
rationale (I said I get uncomfortable every time I see a function
that takes size and nelem separately used by a caller that can
potentially pass nleme=0, when I wondered it it is OK that no caller
of this funtion checks its return value).


>
>>
>> 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
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger•kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-02-26  1:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 22:34 [PATCH] strbuf_write: omit system call when length is zero Stefan Beller
2016-02-25 23:04 ` Junio C Hamano
2016-02-26  0:47 ` Duy Nguyen
2016-02-26  1:40   ` Junio C Hamano [this message]
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=xmqqy4a8l04f.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=Jens.Lehmann@web$(echo .)de \
    --cc=git@vger$(echo .)kernel.org \
    --cc=jrnieder@gmail$(echo .)com \
    --cc=pclouds@gmail$(echo .)com \
    --cc=peff@peff$(echo .)net \
    --cc=sbeller@google$(echo .)com \
    --cc=sunshine@sunshineco$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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