From c61740d6078b6da6219779844cfdd74ed430fb80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 24 Dec 2023 18:02:04 +0100 Subject: mem-pool: simplify alignment calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use DIV_ROUND_UP in mem_pool_alloc() to round the allocation length to the next multiple of GIT_MAX_ALIGNMENT instead of twiddling bits explicitly. This is shorter and clearer, to the point that we no longer need the comment that explains what's being calculated. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- mem-pool.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'mem-pool.c') diff --git a/mem-pool.c b/mem-pool.c index e8d976c3ee..c7d6256020 100644 --- a/mem-pool.c +++ b/mem-pool.c @@ -89,9 +89,7 @@ void *mem_pool_alloc(struct mem_pool *pool, size_t len) struct mp_block *p = NULL; void *r; - /* round up to a 'GIT_MAX_ALIGNMENT' alignment */ - if (len & (GIT_MAX_ALIGNMENT - 1)) - len += GIT_MAX_ALIGNMENT - (len & (GIT_MAX_ALIGNMENT - 1)); + len = DIV_ROUND_UP(len, GIT_MAX_ALIGNMENT) * GIT_MAX_ALIGNMENT; if (pool->mp_block && pool->mp_block->end - pool->mp_block->next_free >= len) -- cgit v1.2.3