Skip to content

Commit c61740d

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6cbae64 commit c61740d

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

mem-pool.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ void *mem_pool_alloc(struct mem_pool *pool, size_t len)
8989
struct mp_block *p = NULL;
9090
void *r;
9191

92-
/* round up to a 'GIT_MAX_ALIGNMENT' alignment */
93-
if (len & (GIT_MAX_ALIGNMENT - 1))
94-
len += GIT_MAX_ALIGNMENT - (len & (GIT_MAX_ALIGNMENT - 1));
92+
len = DIV_ROUND_UP(len, GIT_MAX_ALIGNMENT) * GIT_MAX_ALIGNMENT;
9593

9694
if (pool->mp_block &&
9795
pool->mp_block->end - pool->mp_block->next_free >= len)

0 commit comments

Comments
 (0)