From 6614450da3502e491d6f26f00dad17c8f7825895 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 16:49:03 -0400 Subject: [PATCH] game_list: Make containsAllWords() a non-member function This doesn't depend on class state at all, so this can be made internal. While we're at it, amend the function to take its arguments by const reference. --- src/citra_qt/game_list.cpp | 10 ++++++---- src/citra_qt/game_list.h | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 080165ad4..f2d563a61 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -166,10 +166,12 @@ GameList::SearchField::SearchField(GameList* parent) : QWidget{parent} { * @param String containing all words getting checked * @return true if the haystack contains all words of userinput */ -bool GameList::containsAllWords(QString haystack, QString userinput) { - QStringList userinput_split = userinput.split(" ", QString::SplitBehavior::SkipEmptyParts); +static bool ContainsAllWords(const QString& haystack, const QString& userinput) { + const QStringList userinput_split = + userinput.split(' ', QString::SplitBehavior::SkipEmptyParts); + return std::all_of(userinput_split.begin(), userinput_split.end(), - [haystack](QString s) { return haystack.contains(s); }); + [&haystack](const QString& s) { return haystack.contains(s); }); } // Syncs the expanded state of Game Directories with settings to persist across sessions @@ -223,7 +225,7 @@ void GameList::onTextChanged(const QString& newText) { // The search is case insensitive because of toLower() // I decided not to use Qt::CaseInsensitive in containsAllWords to prevent // multiple conversions of edit_filter_text for each game in the gamelist - if (containsAllWords(file_name.append(" ").append(file_title), edit_filter_text) || + if (ContainsAllWords(file_name.append(' ').append(file_title), edit_filter_text) || (file_programmid.count() == 16 && edit_filter_text.contains(file_programmid))) { tree_view->setRowHidden(j, folder_index, false); ++result_count; diff --git a/src/citra_qt/game_list.h b/src/citra_qt/game_list.h index f600f6ef8..db4897189 100644 --- a/src/citra_qt/game_list.h +++ b/src/citra_qt/game_list.h @@ -115,7 +115,6 @@ private: void DonePopulating(QStringList watch_list); void RefreshGameDirectory(); - bool containsAllWords(QString haystack, QString userinput); void PopupContextMenu(const QPoint& menu_location); void AddGamePopup(QMenu& context_menu, u64 program_id);