diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-03-05 13:11:16 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-03-05 09:10:06 -0800 |
| commit | 7b8abc4d8cd428e4ce044e50f7980baacaccb761 (patch) | |
| tree | c9f0ee85bfca3f477cfb9ed6751edc72a600ec8c /reftable/record.h | |
| parent | e0bd13beea95fa26fa1159a26051f21237f45088 (diff) | |
| download | git-7b8abc4d8cd428e4ce044e50f7980baacaccb761.tar.xz | |
reftable/record: use scratch buffer when decoding records
When decoding log records we need a temporary buffer to decode the
reflog entry's name, mail address and message. As this buffer is local
to the function we thus have to reallocate it for every single log
record which we're about to decode, which is inefficient.
Refactor the code such that callers need to pass in a scratch buffer,
which allows us to reuse it for multiple decodes. This reduces the
number of allocations when iterating through reflogs. Before:
HEAP SUMMARY:
in use at exit: 13,473 bytes in 122 blocks
total heap usage: 2,068,487 allocs, 2,068,365 frees, 305,122,946 bytes allocated
After:
HEAP SUMMARY:
in use at exit: 13,473 bytes in 122 blocks
total heap usage: 1,068,485 allocs, 1,068,363 frees, 281,122,886 bytes allocated
Note that this commit also drop some redundant calls to `strbuf_reset()`
right before calling `decode_string()`. The latter already knows to
reset the buffer, so there is no need for these.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/record.h')
| -rw-r--r-- | reftable/record.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/reftable/record.h b/reftable/record.h index 5e8304e052..826ee1c55c 100644 --- a/reftable/record.h +++ b/reftable/record.h @@ -55,7 +55,8 @@ struct reftable_record_vtable { /* decode data from `src` into the record. */ int (*decode)(void *rec, struct strbuf key, uint8_t extra, - struct string_view src, int hash_size); + struct string_view src, int hash_size, + struct strbuf *scratch); /* deallocate and null the record. */ void (*release)(void *rec); @@ -138,7 +139,7 @@ int reftable_record_encode(struct reftable_record *rec, struct string_view dest, int hash_size); int reftable_record_decode(struct reftable_record *rec, struct strbuf key, uint8_t extra, struct string_view src, - int hash_size); + int hash_size, struct strbuf *scratch); int reftable_record_is_deletion(struct reftable_record *rec); static inline uint8_t reftable_record_type(struct reftable_record *rec) |
