소스 검색

Glenn managed to shrink .text by 5 more bytes.

tags/v0.9.3
Michael Brown 18 년 전
부모
커밋
cfae86f6c8
1개의 변경된 파일6개의 추가작업 그리고 3개의 파일을 삭제
  1. 6
    3
      src/core/malloc.c

+ 6
- 3
src/core/malloc.c 파일 보기

@@ -66,19 +66,22 @@ static LIST_HEAD ( free_blocks );
66 66
  */
67 67
 void * alloc_memblock ( size_t size, size_t align ) {
68 68
 	struct memory_block *block;
69
+	size_t align_mask;
69 70
 	size_t pre_size;
70 71
 	ssize_t post_size;
71 72
 	struct memory_block *pre;
72 73
 	struct memory_block *post;
73 74
 
74
-	/* Round up alignment and size to multiples of MIN_MEMBLOCK_SIZE */
75
-	align = ( align + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 );
75
+	/* Round up size to multiple of MIN_MEMBLOCK_SIZE and
76
+	 * calculate alignment mask.
77
+	 */
76 78
 	size = ( size + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 );
79
+	align_mask = ( align - 1 ) | ( MIN_MEMBLOCK_SIZE - 1 );
77 80
 	DBG ( "Allocating %zx (aligned %zx)\n", size, align );
78 81
 
79 82
 	/* Search through blocks for the first one with enough space */
80 83
 	list_for_each_entry ( block, &free_blocks, list ) {
81
-		pre_size = ( - virt_to_phys ( block ) ) & ( align - 1 );
84
+		pre_size = ( - virt_to_phys ( block ) ) & align_mask;
82 85
 		post_size = block->size - pre_size - size;
83 86
 		if ( post_size >= 0 ) {
84 87
 			/* Split block into pre-block, block, and

Loading…
취소
저장