aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2009-05-03 22:45:46 +0000
committerMax Horn2009-05-03 22:45:46 +0000
commit6a632b51ad7433cc9e04e2e5d68a108e6ba324b4 (patch)
treebefdb91b5960dd819bf9c232e6fcea1a81b6350a /common
parent882c24d2ee9f71640bfc3be811b8dcddd91c9988 (diff)
downloadscummvm-rg350-6a632b51ad7433cc9e04e2e5d68a108e6ba324b4.tar.gz
scummvm-rg350-6a632b51ad7433cc9e04e2e5d68a108e6ba324b4.tar.bz2
scummvm-rg350-6a632b51ad7433cc9e04e2e5d68a108e6ba324b4.zip
COMMON: Optimized MemoryPool::freeUnusedPages (if many pages are phased out at once, don't copy everything multiple times around)
svn-id: r40292
Diffstat (limited to 'common')
-rw-r--r--common/memorypool.cpp14
1 files changed, 8 insertions, 6 deletions
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;