Skip to content

Commit e0bd13b

Browse files
pks-tgitster
authored andcommitted
reftable/record: reuse message when decoding log records
Same as the preceding commit we can allocate log messages as needed when decoding log records, thus further reducing the number of allocations. Before: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 3,068,488 allocs, 3,068,366 frees, 307,122,961 bytes allocated After: 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 Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 193fcb3 commit e0bd13b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

reftable/record.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ static int reftable_log_record_decode(void *rec, struct strbuf key,
871871
switch (r->value_type) {
872872
case REFTABLE_LOG_UPDATE:
873873
FREE_AND_NULL(r->value.update.message);
874+
r->value.update.message_cap = 0;
874875
FREE_AND_NULL(r->value.update.email);
875876
FREE_AND_NULL(r->value.update.name);
876877
break;
@@ -943,8 +944,8 @@ static int reftable_log_record_decode(void *rec, struct strbuf key,
943944
goto done;
944945
string_view_consume(&in, n);
945946

946-
r->value.update.message =
947-
reftable_realloc(r->value.update.message, dest.len + 1);
947+
REFTABLE_ALLOC_GROW(r->value.update.message, dest.len + 1,
948+
r->value.update.message_cap);
948949
memcpy(r->value.update.message, dest.buf, dest.len);
949950
r->value.update.message[dest.len] = 0;
950951

reftable/reftable-record.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct reftable_log_record {
9696
uint64_t time;
9797
int16_t tz_offset;
9898
char *message;
99+
size_t message_cap;
99100
} update;
100101
} value;
101102
};

0 commit comments

Comments
 (0)