diff mbox series

[1/8] reftable/stack: refactor function to gather table sizes

Message ID 5d99191f5c30927f01f9281dcccfa51a120fc698.1722435214.git.ps@pks.im (mailing list archive)
State Superseded
Headers show
Series reftable: improvements and fixes for compaction | expand

Commit Message

Patrick Steinhardt July 31, 2024, 2:14 p.m. UTC
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>
---
 reftable/stack.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Junio C Hamano Aug. 2, 2024, 8:26 p.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

> 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>
> ---
>  reftable/stack.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/reftable/stack.c b/reftable/stack.c
> index 737591125e..ba8234b486 100644
> --- a/reftable/stack.c
> +++ b/reftable/stack.c
> @@ -1305,14 +1305,15 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
>  
>  static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st)
>  {
> -	uint64_t *sizes =
> -		reftable_calloc(st->merged->stack_len, sizeof(*sizes));
>  	int version = (st->opts.hash_id == GIT_SHA1_FORMAT_ID) ? 1 : 2;
>  	int overhead = header_size(version) - 1;
> -	int i = 0;
> -	for (i = 0; i < st->merged->stack_len; i++) {
> +	uint64_t *sizes;
> +
> +	REFTABLE_CALLOC_ARRAY(sizes, st->merged->stack_len);
> +
> +	for (size_t i = 0; i < st->merged->stack_len; i++)
>  		sizes[i] = st->readers[i]->size - overhead;
> -	}
> +

OK.
diff mbox series

Patch

diff --git a/reftable/stack.c b/reftable/stack.c
index 737591125e..ba8234b486 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -1305,14 +1305,15 @@  struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
 
 static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st)
 {
-	uint64_t *sizes =
-		reftable_calloc(st->merged->stack_len, sizeof(*sizes));
 	int version = (st->opts.hash_id == GIT_SHA1_FORMAT_ID) ? 1 : 2;
 	int overhead = header_size(version) - 1;
-	int i = 0;
-	for (i = 0; i < st->merged->stack_len; i++) {
+	uint64_t *sizes;
+
+	REFTABLE_CALLOC_ARRAY(sizes, st->merged->stack_len);
+
+	for (size_t i = 0; i < st->merged->stack_len; i++)
 		sizes[i] = st->readers[i]->size - overhead;
-	}
+
 	return sizes;
 }