* Implemented deleting completely empty chunks.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39598 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-11-23 21:48:32 +00:00
parent 60fed7e077
commit ee72532a7a
+15 -3
View File
@@ -136,13 +136,12 @@ ClientMemoryAllocator::Free(void *cookie)
block_iterator iterator = fFreeBlocks.GetIterator();
struct block* before = NULL;
struct block* after = NULL;
struct block* block;
// TODO: this could be done better if free blocks are sorted,
// and if we had one free blocks list per chunk!
// IOW this is a bit slow...
while ((block = iterator.Next()) != NULL) {
while (struct block* block = iterator.Next()) {
if (block->chunk != freeBlock->chunk)
continue;
@@ -159,17 +158,30 @@ ClientMemoryAllocator::Free(void *cookie)
fFreeBlocks.Remove(after);
free(after);
free(freeBlock);
freeBlock = before;
} else if (before != NULL) {
before->size += freeBlock->size;
free(freeBlock);
freeBlock = before;
} else if (after != NULL) {
after->base -= freeBlock->size;
after->size += freeBlock->size;
free(freeBlock);
freeBlock = after;
} else
fFreeBlocks.Add(freeBlock);
// TODO: check if the whole chunk is free now (we could delete it then)
if (freeBlock->size == freeBlock->chunk->size) {
// We can delete the chunk now
struct chunk* chunk = freeBlock->chunk;
fFreeBlocks.Remove(freeBlock);
free(freeBlock);
fChunks.Remove(chunk);
delete_area(chunk->area);
free(chunk);
}
}