Re: [PATCH v3 03/27] refs/reftable: stop micro-optimizing refname allocations on copy
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 3, 2024, 18:08 UTC
- Message-ID
- <xmqqo78h3nms.fsf@gitster.g>
- In-Reply-To
- <085d90c8b63e937e3d76637ce2422320b5801ebb.1717402403.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> 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???
Show 16 quoted lines
> `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.