Skip to content

Commit

Permalink
LRUCache: Fix Evict() removing too many items
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and refractionpcsx2 committed Sep 9, 2022
1 parent 1e660c8 commit e0cb165
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions common/LRUCache.h
Expand Up @@ -84,7 +84,7 @@ class LRUCache

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();
for (auto iter = m_items.begin(); iter != m_items.end(); ++iter)
Expand All @@ -93,6 +93,7 @@ class LRUCache
lowest = iter;
}
m_items.erase(lowest);
count--;
}
}

Expand All @@ -118,7 +119,7 @@ class LRUCache
{
// evict if we went over
while (m_items.size() > m_max_capacity)
Evict(m_items.size() - (m_max_capacity - 1));
Evict(m_items.size() - m_max_capacity);
}

private:
Expand Down

0 comments on commit e0cb165

Please sign in to comment.