Skip to content

Commit

Permalink
Reallocate memory for bitmaps only when necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brown committed Nov 29, 2007
1 parent 423e9d7 commit 1de705e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/core/bitmap.c
Expand Up @@ -41,14 +41,16 @@ int bitmap_resize ( struct bitmap *bitmap, unsigned int new_length ) {
old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 );
new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 );

new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) );
new_blocks = realloc ( bitmap->blocks, new_size );
if ( ! new_blocks ) {
DBGC ( bitmap, "Bitmap %p could not resize to %d bits\n",
bitmap, new_length );
return -ENOMEM;
if ( old_num_blocks != new_num_blocks ) {
new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) );
new_blocks = realloc ( bitmap->blocks, new_size );
if ( ! new_blocks ) {
DBGC ( bitmap, "Bitmap %p could not resize to %d "
"bits\n", bitmap, new_length );
return -ENOMEM;
}
bitmap->blocks = new_blocks;
}
bitmap->blocks = new_blocks;
bitmap->length = new_length;

while ( old_num_blocks < new_num_blocks ) {
Expand Down

0 comments on commit 1de705e

Please sign in to comment.