From a81a0d8c3eb15e0f9a8bb6a31bc217c54856dedd Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 26 May 2018 19:58:56 +0200 Subject: [PATCH] GameListModel: Don't do a linear scan for each newly added game --- Source/Core/DolphinQt2/GameList/GameListModel.cpp | 14 ++++++++++---- Source/Core/DolphinQt2/GameList/GameListModel.h | 1 + Source/Core/DolphinQt2/GameList/GameTracker.cpp | 11 +++++++---- Source/Core/DolphinQt2/GameList/GameTracker.h | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index 7f26c87435..62fa5e199c 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -17,7 +17,8 @@ const QSize GAMECUBE_BANNER_SIZE(96, 32); GameListModel::GameListModel(QObject* parent) : QAbstractTableModel(parent) { - connect(&m_tracker, &GameTracker::GameLoaded, this, &GameListModel::UpdateGame); + connect(&m_tracker, &GameTracker::GameLoaded, this, &GameListModel::AddGame); + connect(&m_tracker, &GameTracker::GameUpdated, this, &GameListModel::UpdateGame); connect(&m_tracker, &GameTracker::GameRemoved, this, &GameListModel::RemoveGame); connect(&Settings::Instance(), &Settings::PathAdded, &m_tracker, &GameTracker::AddDirectory); connect(&Settings::Instance(), &Settings::PathRemoved, &m_tracker, &GameTracker::RemoveDirectory); @@ -218,14 +219,19 @@ std::shared_ptr GameListModel::GetGameFile(int index) return m_games[index]; } +void GameListModel::AddGame(const std::shared_ptr& game) +{ + beginInsertRows(QModelIndex(), m_games.size(), m_games.size()); + m_games.push_back(game); + endInsertRows(); +} + void GameListModel::UpdateGame(const std::shared_ptr& game) { int index = FindGame(game->GetFilePath()); if (index < 0) { - beginInsertRows(QModelIndex(), m_games.size(), m_games.size()); - m_games.push_back(game); - endInsertRows(); + AddGame(game); } else { diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.h b/Source/Core/DolphinQt2/GameList/GameListModel.h index 921e7535a3..5fc199427d 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.h +++ b/Source/Core/DolphinQt2/GameList/GameListModel.h @@ -52,6 +52,7 @@ public: NUM_COLS }; + void AddGame(const std::shared_ptr& game); void UpdateGame(const std::shared_ptr& game); void RemoveGame(const std::string& path); diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index 4fbde454c1..a9de5e0082 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -89,15 +89,18 @@ void GameTracker::StartInternal() for (const QString& path : m_tracked_files.keys()) paths.push_back(path.toStdString()); - auto emit_game_loaded = [this](const std::shared_ptr& game) { - emit GameLoaded(std::move(game)); + const auto emit_game_loaded = [this](const std::shared_ptr& game) { + emit GameLoaded(game); }; - auto emit_game_removed = [this](const std::string& path) { emit GameRemoved(path); }; + const auto emit_game_updated = [this](const std::shared_ptr& game) { + emit GameUpdated(game); + }; + const auto emit_game_removed = [this](const std::string& path) { emit GameRemoved(path); }; m_initial_games_emitted_event.Wait(); bool cache_updated = m_cache.Update(paths, emit_game_loaded, emit_game_removed); - cache_updated |= m_cache.UpdateAdditionalMetadata(m_title_database, emit_game_loaded); + cache_updated |= m_cache.UpdateAdditionalMetadata(m_title_database, emit_game_updated); if (cache_updated) m_cache.Save(); } diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.h b/Source/Core/DolphinQt2/GameList/GameTracker.h index 3f27475ebc..4f5c87bf4b 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.h +++ b/Source/Core/DolphinQt2/GameList/GameTracker.h @@ -39,7 +39,8 @@ public: void ReloadDirectory(const QString& dir); signals: - void GameLoaded(std::shared_ptr game); + void GameLoaded(const std::shared_ptr& game); + void GameUpdated(const std::shared_ptr& game); void GameRemoved(const std::string& path); private: