[PATCH] malloc: Improve csize2tidx
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Mar 18 19:02:15 GMT 2025
On 18/03/25 09:59, Wilco Dijkstra wrote:
>
> Remove the alignment rounding up from csize2tidx - this makes no sense
> since the input should be a chunk size. Removing it enables further
> optimizations, for example chunksize_nomask can be safely used and
> invalid sizes < MINSIZE are not mapped to a valid tidx.
>
> Passes regress, OK for commit?
>
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 931ca481127c6f5199787058d86a0621328de04b..55fb2ab0ecd5491591e0d04ae38a9bd1088af623 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -298,7 +298,7 @@
> # define tidx2usize(idx) (((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE - SIZE_SZ)
>
> /* When "x" is from chunksize(). */
> -# define csize2tidx(x) (((x) - MINSIZE + MALLOC_ALIGNMENT - 1) / MALLOC_ALIGNMENT)
> +# define csize2tidx(x) (((x) - MINSIZE) / MALLOC_ALIGNMENT)
> /* When "x" is a user-provided size. */
> # define usize2tidx(x) csize2tidx (request2size (x))
>
More information about the Libc-alpha
mailing list