Git development
 help / color / mirror / Atom feed
* [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()
@ 2026-07-14  8:45 René Scharfe
  2026-07-14 16:40 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2026-07-14  8:45 UTC (permalink / raw)
  To: Git List

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);
-
 	/* Translate slopbuf to NULL, as we cannot call realloc on it */
 	if (!sb->alloc)
 		sb->buf = NULL;
-- 
2.55.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()
  2026-07-14  8:45 [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline() René Scharfe
@ 2026-07-14 16:40 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2026-07-14 16:40 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List

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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-14 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14  8:45 [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline() René Scharfe
2026-07-14 16:40 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox