From 6a632b51ad7433cc9e04e2e5d68a108e6ba324b4 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 3 May 2009 22:45:46 +0000 Subject: COMMON: Optimized MemoryPool::freeUnusedPages (if many pages are phased out at once, don't copy everything multiple times around) svn-id: r40292 --- common/memorypool.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/memorypool.cpp b/common/memorypool.cpp index 68da830cf2..d5dcbcc8c8 100644 --- a/common/memorypool.cpp +++ b/common/memorypool.cpp @@ -149,14 +149,16 @@ void MemoryPool::freeUnusedPages() { // printf("freed %d pages out of %d\n", (int)freedPagesCount, (int)_pages.size()); - for (size_t i = 0; i < _pages.size(); ) { - if (_pages[i].start == NULL) { - _pages.remove_at(i); - // We just removed an entry, so we do not advance "i" - } else { - ++i; + // Remove all now unused pages + size_t newSize = 0; + for (size_t i = 0; i < _pages.size(); ++i) { + if (_pages[i].start != NULL) { + if (newSize != i) + _pages[newSize] = _pages[i]; + ++newSize; } } + _pages.resize(newSize); // Reset _chunksPerPage _chunksPerPage = INITIAL_CHUNKS_PER_PAGE; -- cgit v1.2.3