Skip to content

Commit ed7d2f4

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 891ee3b commit ed7d2f4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

reftable/stack.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,14 +1305,15 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
13051305

13061306
static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st)
13071307
{
1308-
uint64_t *sizes =
1309-
reftable_calloc(st->merged->stack_len, sizeof(*sizes));
13101308
int version = (st->opts.hash_id == GIT_SHA1_FORMAT_ID) ? 1 : 2;
13111309
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++)
13141315
sizes[i] = st->readers[i]->size - overhead;
1315-
}
1316+
13161317
return sizes;
13171318
}
13181319

0 commit comments

Comments
 (0)