]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mem-pool: simplify alignment calculation
authorRené Scharfe <l.s.r@web.de>
Sun, 24 Dec 2023 17:02:04 +0000 (18:02 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Dec 2023 20:22:58 +0000 (12:22 -0800)
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 <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mem-pool.c

index e8d976c3eeee6a8c8f0ac5db5c4044e67ec1a5c3..c7d62560201984db8efcb675da9b4ede933c5cbd 100644 (file)
@@ -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)