Thread (58 messages) 58 messages, 4 authors, 2023-12-28

Re: [PATCH v2 04/11] reftable/stack: verify that `reftable_stack_add()` uses auto-compaction

From: Eric Sunshine <hidden>
Date: 2023-12-11 09:36:50

On Mon, Dec 11, 2023 at 4:08 AM Patrick Steinhardt [off-list ref] wrote:
On Fri, Dec 08, 2023 at 06:46:33PM -0500, Eric Sunshine wrote:
quoted
In this case, though, assuming I understand the intent, I think the
more common and safe idiom in this codebase is something like this:

    struct strbuf name = STRBUF_INIT;
    strbuf_addstr(&name, "branch");
    size_t len = name.len;
    for (...) {
        strbuf_setlen(&name, len);
        strbuf_addf(&name, "%04d", i);
        ref.refname = name.buf;
        ...
    }
    strbuf_release(&name);
Yeah, I'll convert this to use a `struct strbuf` instead. But instead of
tracking the length I'll just use a `strbuf_reset()` followed by
`strbuf_addf("branch-%04d")`. It's simpler to read and we don't need to
squeeze every last drop of performance out of this loop anyway.
Sounds perfectly reasonable to me, and I agree with the reasoning,
especially the lower cognitive load with strbuf_reset(). Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help