LRUCache: Fix Evict() removing too many items

This commit is contained in:
Connor McLaughlin 2022-09-08 21:20:07 +10:00 committed by refractionpcsx2
parent 1e660c8e85
commit e0cb165927
1 changed files with 3 additions and 2 deletions

View File

@ -84,7 +84,7 @@ public:
void Evict(std::size_t count = 1) void Evict(std::size_t count = 1)
{ {
while (m_items.size() >= count) while (!m_items.empty() && count > 0)
{ {
typename MapType::iterator lowest = m_items.end(); typename MapType::iterator lowest = m_items.end();
for (auto iter = m_items.begin(); iter != m_items.end(); ++iter) for (auto iter = m_items.begin(); iter != m_items.end(); ++iter)
@ -93,6 +93,7 @@ public:
lowest = iter; lowest = iter;
} }
m_items.erase(lowest); m_items.erase(lowest);
count--;
} }
} }
@ -118,7 +119,7 @@ public:
{ {
// evict if we went over // evict if we went over
while (m_items.size() > m_max_capacity) while (m_items.size() > m_max_capacity)
Evict(m_items.size() - (m_max_capacity - 1)); Evict(m_items.size() - m_max_capacity);
} }
private: private: