From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "René Scharfe" <l.s.r@web.de>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Git List" <git@vger.kernel.org>,
"Victoria Dye" <vdye@github.com>
Subject: Re: [PATCH] cache-tree: fix strbuf growth in prime_cache_tree_rec()
Date: Fri, 10 Feb 2023 21:15:40 -0500 [thread overview]
Message-ID: <Y+b6TAmxel48QHJa@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqwn4pgt1f.fsf@gitster.g>
On Fri, Feb 10, 2023 at 12:33:00PM -0800, Junio C Hamano wrote:
> > strbuf_setlen() truncates the string to the directory name. strbuf_grow() then
> > makes enough room to add that directory name again (that's what I mean with
> > "double") plus the entry path. We don't add the directory name a second time,
> > so we don't need to make room for it.
>
> Yeah, I think I made the same mistake number of years ago, thinking
> that strbuf_grow() was to grow the buffer to the given size, but in
> reality it is to grow the buffer by the given size, which felt a bit
> unnatural, at least to me. I do not feel it too strongly but we
> might want to rename _grow() to _grow_by() and make _grow() call it
> while giving deprecation warning X-<.
Having been confused by that myself, I would be happy to see such a
name change.
> There are ~45 calls to strbuf_grow() in C files other than strbuf.c;
> I suspect probably a half or more of them can and should be removed
> to reduce the resulting code size without hurting anything.
My gut feeling is that your suspicion is giving strbuf_grow() users too
much credit. ;) And having looked at the first 7 grep hits, every single
one of them seemed pointless to me.
I wonder if these would make a good #leftoverbits / micro-project
candidate.
-Peff
next prev parent reply other threads:[~2023-02-11 2:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-04 19:10 [PATCH] cache-tree: fix strbuf growth in prime_cache_tree_rec() René Scharfe
2023-02-05 21:12 ` Ævar Arnfjörð Bjarmason
2023-02-06 15:27 ` Derrick Stolee
2023-02-06 16:18 ` Ævar Arnfjörð Bjarmason
2023-02-12 11:20 ` René Scharfe
2023-02-06 18:55 ` Junio C Hamano
2023-02-10 20:20 ` René Scharfe
2023-02-10 20:20 ` René Scharfe
2023-02-10 20:33 ` Junio C Hamano
2023-02-11 2:15 ` Jeff King [this message]
2023-02-11 2:46 ` Junio C Hamano
2023-02-10 20:20 ` [PATCH v2] " René Scharfe
2023-02-13 13:37 ` Derrick Stolee
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=Y+b6TAmxel48QHJa@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=vdye@github.com \
/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;
as well as URLs for NNTP newsgroup(s).