Re: [PATCH v2] cache-tree: fix strbuf growth in prime_cache_tree_rec()
On 2/10/2023 3:20 PM, René Scharfe wrote:
Show 6 quoted lines
> 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);