SectorReader: Fix cache line bias

Minor bug where SectorReader::GetEmptyCacheLine was biased towards
the first hit.
This commit is contained in:
EmptyChaos
2016-07-06 10:37:59 +00:00
parent 3f03e2d5fe
commit 9036b9d8e8
2 changed files with 11 additions and 8 deletions

View File

@ -57,12 +57,15 @@ SectorReader::Cache* SectorReader::GetEmptyCacheLine()
{
Cache* oldest = &m_cache[0];
// Find the Least Recently Used cache line to replace.
for (auto& cache_entry : m_cache)
{
if (cache_entry.IsLessRecentlyUsedThan(*oldest))
oldest = &cache_entry;
cache_entry.ShiftLRU();
}
std::for_each(m_cache.begin() + 1, m_cache.end(), [&](Cache& line) {
if (line.IsLessRecentlyUsedThan(*oldest))
{
oldest->ShiftLRU();
oldest = &line;
return;
}
line.ShiftLRU();
});
oldest->Reset();
return oldest;
}