Skip to content

Commit

Permalink
mem-pool: simplify alignment calculation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rscharfe authored and gitster committed Dec 28, 2023
1 parent 6cbae64 commit c61740d
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions mem-pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c61740d

Please sign in to comment.