From: René Scharfe Date: Sun, 24 Dec 2023 17:02:04 +0000 (+0100) Subject: mem-pool: simplify alignment calculation X-Git-Tag: v2.44.0-rc0~89^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c61740d6078b6da6219779844cfdd74ed430fb80;p=thirdparty%2Fgit.git mem-pool: simplify alignment calculation 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 --- 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)