From 7b0203b15c1a15c77436160c58b45bef9b087c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 14 Jul 2026 10:45:59 +0200 Subject: [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- 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;