DolphinWX: Use vector instead of list for game list cache

The advantage of std::list is that elements can be removed from the
middle efficiently, but we don't actually need that, because the
ordering of the elements doesn't matter for us. We can just replace the
element we want to remove with the last element and then call pop_back.

Replacing list with vector should speed up looping through the elements.
This commit is contained in:
JosJuice 2018-01-04 17:10:25 +01:00
parent 637fbec35d
commit 04cefc6ed3
2 changed files with 8 additions and 5 deletions

View File

@ -774,7 +774,7 @@ void GameListCtrl::RescanList()
cached_paths.emplace_back(file->GetFileName());
std::sort(cached_paths.begin(), cached_paths.end());
std::list<std::string> removed_paths;
std::vector<std::string> removed_paths;
std::set_difference(cached_paths.cbegin(), cached_paths.cend(), search_results.cbegin(),
search_results.cend(), std::back_inserter(removed_paths));
@ -795,14 +795,17 @@ void GameListCtrl::RescanList()
std::unique_lock<std::mutex> lk(m_cache_mutex);
for (const auto& path : removed_paths)
{
auto it = std::find_if(m_cached_files.cbegin(), m_cached_files.cend(),
auto it = std::find_if(m_cached_files.begin(), m_cached_files.end(),
[&path](const std::shared_ptr<GameListItem>& file) {
return file->GetFileName() == path;
});
if (it != m_cached_files.cend())
if (it != m_cached_files.end())
{
cache_changed = true;
m_cached_files.erase(it);
// Efficiently remove the file without caring about preserving any order
*it = std::move(m_cached_files.back());
m_cached_files.pop_back();
}
}
for (const auto& path : new_paths)

View File

@ -125,7 +125,7 @@ private:
} m_image_indexes;
// Actual backing GameListItems are maintained in a background thread and cached to file
std::list<std::shared_ptr<GameListItem>> m_cached_files;
std::vector<std::shared_ptr<GameListItem>> m_cached_files;
// Locks the list, not the contents
std::mutex m_cache_mutex;
Core::TitleDatabase m_title_database;