reftable/stack: refactor function to gather table sizes

Refactor the function that gathers table sizes to be more idiomatic. For one, use `REFTABLE_CALLOC_ARRAY()` instead of `reftable_calloc()`. Second, avoid using an integer to iterate through the tables in the reftable stack given that `stack_len` itself is using a `size_t`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 8, 2024 at 16:06 UTC ed7d2f4770659be207c0d512bceb337aa18c5527
1 file changed +6 -5
reftable/stack.c
+6 -5
@@ -1305,14 +1305,15 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
1305
1306 static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st)
1307 {
1308 - uint64_t *sizes =
1309 - reftable_calloc(st->merged->stack_len, sizeof(*sizes));
1308 int version = (st->opts.hash_id == GIT_SHA1_FORMAT_ID) ? 1 : 2;
1309 int overhead = header_size(version) - 1;
1312 - int i = 0;
1313 - for (i = 0; i < st->merged->stack_len; i++) {
1310 + uint64_t *sizes;
1311 +
1312 + REFTABLE_CALLOC_ARRAY(sizes, st->merged->stack_len);
1313 +
1314 + for (size_t i = 0; i < st->merged->stack_len; i++)
1315 sizes[i] = st->readers[i]->size - overhead;
1315 - }
1316 +
1317 return sizes;
1318 }
1319