From 575de3d6663273b9d4d8fd483a9b45a971aac3af Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Tue, 18 Mar 2025 12:14:52 +0000 Subject: [PATCH] malloc: Improve csize2tidx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Reviewed-by: Adhemerval Zanella  --- malloc/malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 931ca48112..55fb2ab0ec 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))