mirror of
https://github.com/git/git.git
synced 2024-05-04 19:26:10 +02:00
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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6cbae64000
commit
c61740d607
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue