Subject: Re: [PATCH v3 03/27] refs/reftable: stop micro-optimizing refname allocations on copy

From: Junio C Hamano <[email-masked]>
Date: Mon, 03 Jun 2024 11:08:27 -0700

Patrick Steinhardt <[email-masked]> writes:

> When copying refs, we execute `write_copy_table()` to write the new
> table. As the names arge given to use via `arg->newname` and

arge???

> `arg->oldname`, respectively, we optimize away some allocations by
> assigning those fields to the reftable records we are about to write.
> This requires us to cast the input to `char *` pointers as they are in
> fact constant strings. Later on, we then unset the refname for all of
> the records before calling `reftable_log_record_release()` on them.
>
> We also do this when assigning the "HEAD" constant, but here we do not
> cast because its type is `char[]` by default. It's about to be turned
> into `const char *` though once we enable `-Wwrite-strings` and will
> thus cause another warning.
>
> It's quite dubious whether this micro-optimization really helps. We're
> about to write to disk anyway, which is going to be way slower than a
> small handful of allocations. Let's drop the optimization altogther and
> instead copy arguments to simplify the code and avoid the future warning
> with `-Wwrite-strings`.

It certainly makes the final clean-up part simpler, which is a good
sign.