Re: [hackers] [sbase][PATCH] sort: Keep the "cap" field updated
Hi,
On Fri, Aug 29, 2025 at 10:20:35AM -0700, Matthew Sotoudeh wrote:
> Sorry if I'm misunderstanding the code, but it appears to me that
Sorry in my case for the long delay, I had some changes in my personal
life and I had to push back the work in sbase. Trying to catch up
with the pending changes now.
> a944b682a694b4e7900c94d6550845f8d52af574 forgot to update the "cap"
> field upon resizing column arrays, making it always 0 and causing
> unnecessary allocations. This commit fixes that by keeping the "cap"
> field updated.
I think you are right, cap was not ever updated.
> ---
> sort.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/sort.c b/sort.c
> index fbb1abf..99376ca 100644
> --- a/sort.c
> +++ b/sort.c
> _AT_@ -126,6 +126,7 @@ columns(struct line *line, const struct keydef *kd, struct column *col)
> if (!(col->line.data) || col->cap < col->line.len + 1) {
> free(col->line.data);
> col->line.data = emalloc(col->line.len + 1);
> + col->cap = col->line.len + 1;
> }
Usually, when you use a cap field then you prealloce additional
space to avoid additional calls to realloc. But in this specific
case we dont reuse previous data in any case, so I think your
change is good. I pushed with a small change in the commit
description. Thank you!
Regards,
Received on Thu Oct 09 2025 - 11:14:49 CEST
This archive was generated by hypermail 2.3.0
: Thu Oct 09 2025 - 11:24:39 CEST