Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()
Date: Tue, 14 Jul 2026 09:40:12 -0700	[thread overview]
Message-ID: <xmqq8q7dv82b.fsf@gitster.g> (raw)
In-Reply-To: <d4ffe7fb-f782-4f06-9e3b-f72729d1e225@web.de> ("René Scharfe"'s message of "Tue, 14 Jul 2026 10:45:59 +0200")

René Scharfe <l.s.r@web.de> writes:

> The HAVE_GETDELIM variant of strbuf_getwholeline() calls strbuf_reset()
> on the strbuf before handing it over to getdelim(3).  This is
> unnecessary:
>
>   - getdelim(3) doesn't care whether the old buffer contents is
>     NUL-terminated and has no access to ->len,
>   - on success getdelim(3) NUL-terminates the buffer and we set ->len,
>   - on error we either call strbuf_init() or strbuf_reset().
>
> Remove the superfluous preparatory call.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  strbuf.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/strbuf.c b/strbuf.c
> index 764b629927..44955669e8 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -646,8 +646,6 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
>  	if (feof(fp))
>  		return EOF;
>  
> -	strbuf_reset(sb);
> -

This is well explained and makes perfect sense.

Thanks.  Will apply and mark for 'next'.

>  	/* Translate slopbuf to NULL, as we cannot call realloc on it */
>  	if (!sb->alloc)
>  		sb->buf = NULL;

  reply	other threads:[~2026-07-14 16:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14  8:45 [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline() René Scharfe
2026-07-14 16:40 ` Junio C Hamano [this message]
2026-07-14 21:49 ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq8q7dv82b.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /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