COMMON: Optimized MemoryPool::freeUnusedPages (if many pages are phased out at once, don't copy everything multiple times around)

svn-id: r40292
This commit is contained in:
Max Horn 2009-05-03 22:45:46 +00:00
parent 882c24d2ee
commit 6a632b51ad

View File

@ -149,14 +149,16 @@ void MemoryPool::freeUnusedPages() {
// printf("freed %d pages out of %d\n", (int)freedPagesCount, (int)_pages.size()); // printf("freed %d pages out of %d\n", (int)freedPagesCount, (int)_pages.size());
for (size_t i = 0; i < _pages.size(); ) { // Remove all now unused pages
if (_pages[i].start == NULL) { size_t newSize = 0;
_pages.remove_at(i); for (size_t i = 0; i < _pages.size(); ++i) {
// We just removed an entry, so we do not advance "i" if (_pages[i].start != NULL) {
} else { if (newSize != i)
++i; _pages[newSize] = _pages[i];
++newSize;
} }
} }
_pages.resize(newSize);
// Reset _chunksPerPage // Reset _chunksPerPage
_chunksPerPage = INITIAL_CHUNKS_PER_PAGE; _chunksPerPage = INITIAL_CHUNKS_PER_PAGE;