From cfae86f6c8f9103422abb62d23d33e44b06e1906 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 25 Apr 2006 21:48:16 +0000 Subject: [PATCH] Glenn managed to shrink .text by 5 more bytes. --- src/core/malloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/malloc.c b/src/core/malloc.c index bead02ed..f6d0ffde 100644 --- a/src/core/malloc.c +++ b/src/core/malloc.c @@ -66,19 +66,22 @@ static LIST_HEAD ( free_blocks ); */ void * alloc_memblock ( size_t size, size_t align ) { struct memory_block *block; + size_t align_mask; size_t pre_size; ssize_t post_size; struct memory_block *pre; struct memory_block *post; - /* Round up alignment and size to multiples of MIN_MEMBLOCK_SIZE */ - align = ( align + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 ); + /* Round up size to multiple of MIN_MEMBLOCK_SIZE and + * calculate alignment mask. + */ size = ( size + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 ); + align_mask = ( align - 1 ) | ( MIN_MEMBLOCK_SIZE - 1 ); DBG ( "Allocating %zx (aligned %zx)\n", size, align ); /* Search through blocks for the first one with enough space */ list_for_each_entry ( block, &free_blocks, list ) { - pre_size = ( - virt_to_phys ( block ) ) & ( align - 1 ); + pre_size = ( - virt_to_phys ( block ) ) & align_mask; post_size = block->size - pre_size - size; if ( post_size >= 0 ) { /* Split block into pre-block, block, and