From: Derrick Stolee <derrickstolee@github.com>
To: "René Scharfe" <l.s.r@web.de>, "Git List" <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Victoria Dye" <vdye@github.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
Subject: Re: [PATCH v2] cache-tree: fix strbuf growth in prime_cache_tree_rec()
Date: Mon, 13 Feb 2023 08:37:36 -0500 [thread overview]
Message-ID: <7c8b6420-fe69-a190-9197-0ddbb3e4a964@github.com> (raw)
In-Reply-To: <a37623c8-d2fb-aec6-3423-2d402d717959@web.de>
On 2/10/2023 3:20 PM, René Scharfe wrote:
> Use size_t to store the original length of the strbuf tree_len, as
> that's the correct type.
>
> Don't double the allocated size of the strbuf when adding a subdirectory
> name. And the chance of the trailing slash fitting in the slack left by
> strbuf_add() is very high, so stop pre-growing the strbuf at all.
> - int base_path_len = tree_path->len;
> + size_t base_path_len = tree_path->len;
> strbuf_setlen(tree_path, base_path_len);
> - strbuf_grow(tree_path, base_path_len + entry.pathlen + 1);
> strbuf_add(tree_path, entry.path, entry.pathlen);
Excellent. LGTM.
-Stolee
prev parent reply other threads:[~2023-02-13 13:37 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
2023-02-11 2:46 ` Junio C Hamano
2023-02-10 20:20 ` [PATCH v2] " René Scharfe
2023-02-13 13:37 ` Derrick Stolee [this message]
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=7c8b6420-fe69-a190-9197-0ddbb3e4a964@github.com \
--to=derrickstolee@github.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--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).