git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] strbuf_write: omit system call when length is zero

From
Duy Nguyen <pclouds@gmail.com>
Date
Feb 26, 2016, 00:47 UTC
Message-ID
<CACsJy8DgjmdX681fRwB-JajPBRN+cNy=jFwEDW6D-dXhNi=_6g@mail.gmail.com>
In-Reply-To
<1456439678-5433-1-git-send-email-sbeller@google.com>
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)?

Show 39 quoted lines
>
> 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
-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 5 in “strbuf_write: omit system call when length is zero”
  1. strbuf_write: omit system call when length is zeroStefan Beller, Feb 25, 2016
  2. Junio C HamanoFeb 25, 2016
  3. Duy NguyenFeb 26, 2016
  4. Junio C HamanoFeb 26, 2016
  5. Stefan BellerFeb 26, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.