david/ipxe
Archived
1
0

Reallocate memory for bitmaps only when necessary.

This commit is contained in:
Michael Brown 2007-11-29 19:10:10 +00:00
parent 423e9d72f3
commit 1de705e30f

View File

@ -41,14 +41,16 @@ int bitmap_resize ( struct bitmap *bitmap, unsigned int new_length ) {
old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 ); old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 );
new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 ); new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 );
new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) ); if ( old_num_blocks != new_num_blocks ) {
new_blocks = realloc ( bitmap->blocks, new_size ); new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) );
if ( ! new_blocks ) { new_blocks = realloc ( bitmap->blocks, new_size );
DBGC ( bitmap, "Bitmap %p could not resize to %d bits\n", if ( ! new_blocks ) {
bitmap, new_length ); DBGC ( bitmap, "Bitmap %p could not resize to %d "
return -ENOMEM; "bits\n", bitmap, new_length );
return -ENOMEM;
}
bitmap->blocks = new_blocks;
} }
bitmap->blocks = new_blocks;
bitmap->length = new_length; bitmap->length = new_length;
while ( old_num_blocks < new_num_blocks ) { while ( old_num_blocks < new_num_blocks ) {