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

Re: [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 14, 2026, 16:40 UTC
Message-ID
<xmqq8q7dv82b.fsf@gitster.g>
In-Reply-To
<d4ffe7fb-f782-4f06-9e3b-f72729d1e225@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 26 quoted lines
> 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;
Previous: René ScharfeNext: Jeff King
Message 2 of 3 in “strbuf: avoid redundant reset in strbuf_getwholeline()”
  1. strbuf: avoid redundant reset in strbuf_getwholeline()René Scharfe, Jul 14, 2026
  2. Junio C HamanoJul 14, 2026
  3. Jeff KingJul 14, 2026

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.