From 764bf314e11431171a8890264d423a66aaff23c3 Mon Sep 17 00:00:00 2001 From: Gamer64 <76565986+Gamer64ytb@users.noreply.github.com> Date: Tue, 24 Dec 2024 10:41:45 +0100 Subject: [PATCH 1/8] Android: Fix VSync option not working It happened due to a typo from SECTION_GFX_HARDWARE --- .../dolphinemu/dolphinemu/features/settings/model/Settings.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt index a971d7b709..d9736fd84d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt @@ -124,7 +124,7 @@ class Settings : Closeable { const val SECTION_INI_DSP = "DSP" const val SECTION_LOGGER_LOGS = "Logs" const val SECTION_LOGGER_OPTIONS = "Options" - const val SECTION_GFX_HARDWARE = "Settings" + const val SECTION_GFX_HARDWARE = "Hardware" const val SECTION_GFX_SETTINGS = "Settings" const val SECTION_GFX_ENHANCEMENTS = "Enhancements" const val SECTION_GFX_COLOR_CORRECTION = "ColorCorrection" From bae4616dd1eb756891f193a8e56b9bc9c80fba41 Mon Sep 17 00:00:00 2001 From: Niel Lebeck Date: Thu, 26 Dec 2024 11:40:09 -0800 Subject: [PATCH 2/8] Add some unit test coverage of the SplitPath function --- Source/UnitTests/Common/StringUtilTest.cpp | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/Source/UnitTests/Common/StringUtilTest.cpp b/Source/UnitTests/Common/StringUtilTest.cpp index f887157d52..abf37be585 100644 --- a/Source/UnitTests/Common/StringUtilTest.cpp +++ b/Source/UnitTests/Common/StringUtilTest.cpp @@ -81,3 +81,114 @@ TEST(StringUtil, GetEscapedHtml) EXPECT_EQ(Common::GetEscapedHtml("&<>'\""), "&<>'""); EXPECT_EQ(Common::GetEscapedHtml("&&&"), "&&&"); } + +TEST(StringUtil, SplitPath) +{ + std::string path; + std::string filename; + std::string extension; + EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", &path, &filename, &extension)); + EXPECT_EQ(path, "/usr/lib/"); + EXPECT_EQ(filename, "some_file"); + EXPECT_EQ(extension, ".txt"); +} + +TEST(StringUtil, SplitPathNullOutputPathAllowed) +{ + std::string filename; + std::string extension; + EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", /*path=*/nullptr, &filename, &extension)); + EXPECT_EQ(filename, "some_file"); + EXPECT_EQ(extension, ".txt"); +} + +TEST(StringUtil, SplitPathNullOutputFilenameAllowed) +{ + std::string path; + std::string extension; + EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", &path, /*filename=*/nullptr, &extension)); + EXPECT_EQ(path, "/usr/lib/"); + EXPECT_EQ(extension, ".txt"); +} + +TEST(StringUtil, SplitPathNullOutputExtensionAllowed) +{ + std::string path; + std::string filename; + EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", &path, &filename, /*extension=*/nullptr)); + EXPECT_EQ(path, "/usr/lib/"); + EXPECT_EQ(filename, "some_file"); +} + +TEST(StringUtil, SplitPathReturnsFalseIfFullPathIsEmpty) +{ + std::string path; + std::string filename; + std::string extension; + EXPECT_FALSE(SplitPath(/*full_path=*/"", &path, &filename, &extension)); + EXPECT_EQ(path, ""); + EXPECT_EQ(filename, ""); + EXPECT_EQ(extension, ""); +} + +TEST(StringUtil, SplitPathNoPath) +{ + std::string path; + std::string filename; + std::string extension; + EXPECT_TRUE(SplitPath("some_file.txt", &path, &filename, &extension)); + EXPECT_EQ(path, ""); + EXPECT_EQ(filename, "some_file"); + EXPECT_EQ(extension, ".txt"); +} + +TEST(StringUtil, SplitPathNoFileName) +{ + std::string path; + std::string filename; + std::string extension; + EXPECT_TRUE(SplitPath("/usr/lib/.txt", &path, &filename, &extension)); + EXPECT_EQ(path, "/usr/lib/"); + EXPECT_EQ(filename, ""); + EXPECT_EQ(extension, ".txt"); +} + +TEST(StringUtil, SplitPathNoExtension) +{ + std::string path; + std::string filename; + std::string extension; + EXPECT_TRUE(SplitPath("/usr/lib/some_file", &path, &filename, &extension)); + EXPECT_EQ(path, "/usr/lib/"); + EXPECT_EQ(filename, "some_file"); + EXPECT_EQ(extension, ""); +} + +TEST(StringUtil, SplitPathDifferentPathLengths) +{ + std::string path; + std::string filename; + std::string extension; + EXPECT_TRUE(SplitPath("/usr/some_file.txt", &path, &filename, &extension)); + EXPECT_EQ(path, "/usr/"); + EXPECT_EQ(filename, "some_file"); + EXPECT_EQ(extension, ".txt"); + + EXPECT_TRUE(SplitPath("/usr/lib/foo/some_file.txt", &path, &filename, &extension)); + EXPECT_EQ(path, "/usr/lib/foo/"); + EXPECT_EQ(filename, "some_file"); + EXPECT_EQ(extension, ".txt"); +} + +TEST(StringUtil, SplitPathBackslashesNotRecognizedAsSeparators) +{ + std::string path; + std::string filename; + std::string extension; + EXPECT_TRUE(SplitPath("\\usr\\some_file.txt", &path, &filename, &extension)); + EXPECT_EQ(path, ""); + EXPECT_EQ(filename, "\\usr\\some_file"); + EXPECT_EQ(extension, ".txt"); +} + +// TODO: add `SplitPath` test coverage for paths containing Windows drives, e.g., "C:". From 98ee3836e578043c2ba5c6ab9ac90f891c94d283 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 25 Dec 2024 04:31:03 +0100 Subject: [PATCH 3/8] DolphinQt: Add option for value mappings to ConfigSlider --- .../Config/ConfigControls/ConfigSlider.cpp | 50 ++++++++++++++++++- .../Config/ConfigControls/ConfigSlider.h | 10 ++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.cpp index a296d57e86..349e73eeda 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.cpp @@ -1,6 +1,8 @@ // Copyright 2017 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include + #include #include "DolphinQt/Config/ConfigControls/ConfigSlider.h" @@ -24,14 +26,58 @@ ConfigSlider::ConfigSlider(int minimum, int maximum, const Config::Info& se connect(this, &ConfigSlider::valueChanged, this, &ConfigSlider::Update); } +ConfigSlider::ConfigSlider(std::vector tick_values, const Config::Info& setting, + Config::Layer* layer) + : ConfigControl(Qt::Horizontal, setting.GetLocation(), layer), m_setting(setting), + m_tick_values(std::move(tick_values)) +{ + assert(!m_tick_values.empty()); + setMinimum(0); + setMaximum(static_cast(m_tick_values.size() - 1)); + setPageStep(1); + setTickPosition(QSlider::TicksBelow); + OnConfigChanged(); + + connect(this, &ConfigSlider::valueChanged, this, &ConfigSlider::Update); +} + void ConfigSlider::Update(int value) { - SaveValue(m_setting, value); + if (!m_tick_values.empty()) + { + if (value >= 0 && static_cast(value) < m_tick_values.size()) + SaveValue(m_setting, m_tick_values[static_cast(value)]); + } + else + { + SaveValue(m_setting, value); + } } void ConfigSlider::OnConfigChanged() { - setValue(ReadValue(m_setting)); + if (!m_tick_values.empty()) + { + // re-enable in case it was disabled + setEnabled(true); + + const int config_value = ReadValue(m_setting); + for (size_t i = 0; i < m_tick_values.size(); ++i) + { + if (m_tick_values[i] == config_value) + { + setValue(static_cast(i)); + return; + } + } + + // if we reach here than none of the options matched, disable the slider + setEnabled(false); + } + else + { + setValue(ReadValue(m_setting)); + } } ConfigSliderLabel::ConfigSliderLabel(const QString& text, ConfigSlider* slider) diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.h b/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.h index 3df98d53b7..ec1ba827ad 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.h +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigSlider.h @@ -3,6 +3,8 @@ #pragma once +#include + #include #include @@ -19,6 +21,11 @@ public: ConfigSlider(int minimum, int maximum, const Config::Info& setting, Config::Layer* layer, int tick = 0); + // Generates a slider with tick_values.size() ticks. Each tick corresponds to the integer at that + // index in the vector. + ConfigSlider(std::vector tick_values, const Config::Info& setting, + Config::Layer* layer); + void Update(int value); protected: @@ -26,6 +33,9 @@ protected: private: const Config::Info m_setting; + + // Mappings for slider ticks to config values. Identity mapping is assumed if this is empty. + std::vector m_tick_values; }; class ConfigSliderLabel final : public QLabel From 4fc50226c63dc00994444f1113258e6726b63caa Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 25 Dec 2024 04:39:56 +0100 Subject: [PATCH 4/8] DolphinQt/HacksWidget: Convert accuracy slider to ConfigSlider --- .../DolphinQt/Config/Graphics/HacksWidget.cpp | 78 ++----------------- .../DolphinQt/Config/Graphics/HacksWidget.h | 9 +-- 2 files changed, 9 insertions(+), 78 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp index 49a1c50b68..da32111155 100644 --- a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp @@ -25,23 +25,18 @@ HacksWidget::HacksWidget(GraphicsWindow* parent) { CreateWidgets(); - LoadSettings(); ConnectWidgets(); AddDescriptions(); connect(parent, &GraphicsWindow::BackendChanged, this, &HacksWidget::OnBackendChanged); OnBackendChanged(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND))); - connect(&Settings::Instance(), &Settings::ConfigChanged, this, &HacksWidget::LoadSettings); - connect(m_gpu_texture_decoding, &QCheckBox::toggled, [this, parent] { - SaveSettings(); - emit parent->UseGPUTextureDecodingChanged(); - }); + connect(m_gpu_texture_decoding, &QCheckBox::toggled, + [this, parent] { emit parent->UseGPUTextureDecodingChanged(); }); } HacksWidget::HacksWidget(GameConfigWidget* parent, Config::Layer* layer) : m_game_layer(layer) { CreateWidgets(); - LoadSettings(); ConnectWidgets(); AddDescriptions(); } @@ -73,18 +68,15 @@ void HacksWidget::CreateWidgets() auto* texture_cache_layout = new QGridLayout(); texture_cache_box->setLayout(texture_cache_layout); - m_accuracy = new ToolTipSlider(Qt::Horizontal); - m_accuracy->setMinimum(0); - m_accuracy->setMaximum(2); - m_accuracy->setPageStep(1); - m_accuracy->setTickPosition(QSlider::TicksBelow); + m_accuracy = + new ConfigSlider({0, 512, 128}, Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, m_game_layer); m_gpu_texture_decoding = new ConfigBool(tr("GPU Texture Decoding"), Config::GFX_ENABLE_GPU_TEXTURE_DECODING, m_game_layer); auto* safe_label = new QLabel(tr("Safe")); safe_label->setAlignment(Qt::AlignRight); - m_accuracy_label = new QLabel(tr("Accuracy:")); + m_accuracy_label = new ConfigSliderLabel(tr("Accuracy:"), m_accuracy); texture_cache_layout->addWidget(m_accuracy_label, 0, 0); texture_cache_layout->addWidget(safe_label, 0, 1); @@ -158,7 +150,6 @@ void HacksWidget::OnBackendChanged(const QString& backend_name) void HacksWidget::ConnectWidgets() { - connect(m_accuracy, &QSlider::valueChanged, [this](int) { SaveSettings(); }); connect(m_store_efb_copies, &QCheckBox::stateChanged, [this](int) { UpdateDeferEFBCopiesEnabled(); }); connect(m_store_xfb_copies, &QCheckBox::stateChanged, @@ -169,65 +160,6 @@ void HacksWidget::ConnectWidgets() [this](int) { UpdateSkipPresentingDuplicateFramesEnabled(); }); } -void HacksWidget::LoadSettings() -{ - const QSignalBlocker blocker(m_accuracy); - auto samples = Config::Get(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES); - - // Re-enable the slider in case it was disabled because of a custom value - m_accuracy->setEnabled(true); - - int slider_pos = 0; - - switch (samples) - { - case 512: - slider_pos = 1; - break; - case 128: - slider_pos = 2; - break; - case 0: - slider_pos = 0; - break; - // Custom values, ought not to be touched - default: - m_accuracy->setEnabled(false); - } - - m_accuracy->setValue(slider_pos); - - QFont bf = m_accuracy_label->font(); - - bf.setBold(Config::GetActiveLayerForConfig(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES) != - Config::LayerType::Base); - - m_accuracy_label->setFont(bf); -} - -void HacksWidget::SaveSettings() -{ - int slider_pos = m_accuracy->value(); - - if (m_accuracy->isEnabled()) - { - int samples = 0; - switch (slider_pos) - { - case 0: - samples = 0; - break; - case 1: - samples = 512; - break; - case 2: - samples = 128; - } - - Config::SetBaseOrCurrent(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, samples); - } -} - void HacksWidget::AddDescriptions() { static const char TR_SKIP_EFB_CPU_ACCESS_DESCRIPTION[] = QT_TR_NOOP( diff --git a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h index 391570278c..3683c36075 100644 --- a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h +++ b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h @@ -6,6 +6,8 @@ #include class ConfigBool; +class ConfigSlider; +class ConfigSliderLabel; class GameConfigWidget; class GraphicsWindow; class QLabel; @@ -24,9 +26,6 @@ public: HacksWidget(GameConfigWidget* parent, Config::Layer* layer); private: - void LoadSettings(); - void SaveSettings(); - void OnBackendChanged(const QString& backend_name); // EFB @@ -36,8 +35,8 @@ private: ConfigBool* m_defer_efb_copies; // Texture Cache - QLabel* m_accuracy_label; - ToolTipSlider* m_accuracy; + ConfigSliderLabel* m_accuracy_label; + ConfigSlider* m_accuracy; ConfigBool* m_gpu_texture_decoding; // External Framebuffer From 6f10acea3fee4d08c4e52e66f862da45ad06d1ed Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sun, 29 Sep 2024 14:29:06 -0700 Subject: [PATCH 5/8] Common: Create "Contains.h" Algorithm Header The new `Common::Contains` and `Common::ContainsSubrange` function objects mirror C++23's `std::ranges::contains` and `std::ranges::contains_subrange`, respectively. --- Source/Core/Common/CMakeLists.txt | 1 + Source/Core/Common/Contains.h | 61 +++++++++++++++++++++++++++++++ Source/Core/DolphinLib.props | 1 + 3 files changed, 63 insertions(+) create mode 100644 Source/Core/Common/Contains.h diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 81431e564c..d7262eaa4e 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -34,6 +34,7 @@ add_library(common Config/Enums.h Config/Layer.cpp Config/Layer.h + Contains.h CPUDetect.h Crypto/AES.cpp Crypto/AES.h diff --git a/Source/Core/Common/Contains.h b/Source/Core/Common/Contains.h new file mode 100644 index 0000000000..f707cb0f82 --- /dev/null +++ b/Source/Core/Common/Contains.h @@ -0,0 +1,61 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +namespace Common +{ +struct ContainsFn +{ + template S, class T, class Proj = std::identity> + requires std::indirect_binary_predicate < std::ranges::equal_to, std::projected, + const T* > constexpr bool operator()(I first, S last, const T& value, Proj proj = {}) const + { + return std::ranges::find(std::move(first), last, value, std::move(proj)) != last; + } + + template + requires std::indirect_binary_predicate < std::ranges::equal_to, + std::projected, Proj>, + const T* > constexpr bool operator()(R&& r, const T& value, Proj proj = {}) const + { + return (*this)(std::ranges::begin(r), std::ranges::end(r), value, std::move(proj)); + } +}; + +struct ContainsSubrangeFn +{ + template S1, std::forward_iterator I2, + std::sentinel_for S2, class Pred = std::ranges::equal_to, + class Proj1 = std::identity, class Proj2 = std::identity> + requires std::indirectly_comparable + constexpr bool operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, + Proj1 proj1 = {}, Proj2 proj2 = {}) const + { + return !std::ranges::search(std::move(first1), std::move(last1), std::move(first2), + std::move(last2), std::move(pred), std::move(proj1), + std::move(proj2)) + .empty(); + } + + template + requires std::indirectly_comparable, std::ranges::iterator_t, + Pred, Proj1, Proj2> + constexpr bool operator()(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, + Proj2 proj2 = {}) const + { + return (*this)(std::ranges::begin(r1), std::ranges::end(r1), std::ranges::begin(r2), + std::ranges::end(r2), std::move(pred), std::move(proj1), std::move(proj2)); + } +}; + +// TODO C++23: Replace with std::ranges::contains. +inline constexpr ContainsFn Contains{}; +// TODO C++23: Replace with std::ranges::contains_subrange. +inline constexpr ContainsSubrangeFn ContainsSubrange{}; +} // namespace Common diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index a61f0d822a..e41e9fc26a 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -38,6 +38,7 @@ + From 110d32729ecbe5b19df9b2cc76de630334410589 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:17:29 -0700 Subject: [PATCH 6/8] Simplify `std::find` with `Common::Contains` In NandPaths.cpp, the `std::initializer_list` of illegal characters has been turned into a `char[]` (similar to the one in GameList.cpp). The reverse iteration in ResourcePack.cpp seemed to provide no benefits, and doing without it it seemed to have no ill effects. --- Source/Core/Common/NandPaths.cpp | 6 +++--- Source/Core/Core/Config/DefaultLocale.cpp | 11 ++++------- Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp | 4 ++-- Source/Core/Core/Debugger/CodeTrace.cpp | 10 ++++------ Source/Core/Core/Debugger/PPCDebugInterface.cpp | 3 ++- Source/Core/Core/WC24PatchEngine.cpp | 6 ++---- Source/Core/DiscIO/VolumeVerifier.cpp | 12 +++++------- Source/Core/DolphinQt/GameList/GameList.cpp | 4 ++-- .../Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp | 3 ++- Source/Core/DolphinQt/Settings.cpp | 3 ++- .../ControllerInterface/Android/Android.cpp | 4 ++-- Source/Core/UICommon/ResourcePack/ResourcePack.cpp | 12 ++++-------- Source/Core/UICommon/X11Utils.cpp | 3 ++- .../GraphicsModSystem/Runtime/CustomPipeline.cpp | 5 +++-- Source/Core/VideoCommon/VertexManagerBase.cpp | 4 ++-- Source/Core/VideoCommon/VideoConfig.cpp | 4 ++-- 16 files changed, 43 insertions(+), 51 deletions(-) diff --git a/Source/Core/Common/NandPaths.cpp b/Source/Core/Common/NandPaths.cpp index 65d18d0c70..db2c2f0cf3 100644 --- a/Source/Core/Common/NandPaths.cpp +++ b/Source/Core/Common/NandPaths.cpp @@ -11,6 +11,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/Contains.h" #include "Common/FileUtil.h" #include "Common/StringUtil.h" @@ -105,9 +106,8 @@ bool IsTitlePath(const std::string& path, std::optional from, u64 static bool IsIllegalCharacter(char c) { - static constexpr auto illegal_chars = {'\"', '*', '/', ':', '<', '>', '?', '\\', '|', '\x7f'}; - return static_cast(c) <= 0x1F || - std::find(illegal_chars.begin(), illegal_chars.end(), c) != illegal_chars.end(); + static constexpr char illegal_chars[] = {'\"', '*', '/', ':', '<', '>', '?', '\\', '|', '\x7f'}; + return static_cast(c) <= 0x1F || Common::Contains(illegal_chars, c); } std::string EscapeFileName(const std::string& filename) diff --git a/Source/Core/Core/Config/DefaultLocale.cpp b/Source/Core/Core/Config/DefaultLocale.cpp index 3610e42902..019bebf4fb 100644 --- a/Source/Core/Core/Config/DefaultLocale.cpp +++ b/Source/Core/Core/Config/DefaultLocale.cpp @@ -17,6 +17,7 @@ #include "Common/Assert.h" #include "Common/CommonTypes.h" +#include "Common/Contains.h" #include "Common/StringUtil.h" #include "Core/Host.h" #include "DiscIO/Enums.h" @@ -38,17 +39,13 @@ static std::optional TryParseLanguage(const std::string& local // Special handling of Chinese due to its two writing systems if (split_locale[0] == "zh") { - const auto locale_contains = [&split_locale](std::string_view str) { - return std::find(split_locale.cbegin(), split_locale.cend(), str) != split_locale.cend(); - }; - - if (locale_contains("Hans")) + if (Common::Contains(split_locale, "Hans")) return DiscIO::Language::SimplifiedChinese; - if (locale_contains("Hant")) + if (Common::Contains(split_locale, "Hant")) return DiscIO::Language::TraditionalChinese; // Mainland China and Singapore use simplified characters - if (locale_contains("CN") || locale_contains("SG")) + if (Common::Contains(split_locale, "CN") || Common::Contains(split_locale, "SG")) return DiscIO::Language::SimplifiedChinese; else return DiscIO::Language::TraditionalChinese; diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 0a0230d697..9527c8ad7e 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -6,6 +6,7 @@ #include #include +#include "Common/Contains.h" #include "Core/Config/WiimoteSettings.h" namespace ConfigLoaders @@ -15,8 +16,7 @@ bool IsSettingSaveable(const Config::Location& config_location) static constexpr std::array systems_not_saveable = {Config::System::GCPad, Config::System::WiiPad, Config::System::GCKeyboard}; - if (std::find(begin(systems_not_saveable), end(systems_not_saveable), config_location.system) == - end(systems_not_saveable)) + if (!Common::Contains(systems_not_saveable, config_location.system)) { return true; } diff --git a/Source/Core/Core/Debugger/CodeTrace.cpp b/Source/Core/Core/Debugger/CodeTrace.cpp index b92bc246eb..f90681a488 100644 --- a/Source/Core/Core/Debugger/CodeTrace.cpp +++ b/Source/Core/Core/Debugger/CodeTrace.cpp @@ -7,6 +7,7 @@ #include #include +#include "Common/Contains.h" #include "Common/Event.h" #include "Core/Core.h" #include "Core/Debugger/PPCDebugInterface.h" @@ -254,12 +255,9 @@ HitType CodeTrace::TraceLogic(const TraceOutput& current_instr, bool first_hit) // The reg_itr will be used later for erasing. auto reg_itr = std::ranges::find(m_reg_autotrack, instr.reg0); const bool match_reg123 = - (!instr.reg1.empty() && std::find(m_reg_autotrack.begin(), m_reg_autotrack.end(), - instr.reg1) != m_reg_autotrack.end()) || - (!instr.reg2.empty() && std::find(m_reg_autotrack.begin(), m_reg_autotrack.end(), - instr.reg2) != m_reg_autotrack.end()) || - (!instr.reg3.empty() && std::find(m_reg_autotrack.begin(), m_reg_autotrack.end(), - instr.reg3) != m_reg_autotrack.end()); + (!instr.reg1.empty() && Common::Contains(m_reg_autotrack, instr.reg1)) || + (!instr.reg2.empty() && Common::Contains(m_reg_autotrack, instr.reg2)) || + (!instr.reg3.empty() && Common::Contains(m_reg_autotrack, instr.reg3)); const bool match_reg0 = reg_itr != m_reg_autotrack.end(); if (!match_reg0 && !match_reg123 && !mem_hit) diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index 626e18c067..2c840d0ae5 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -13,6 +13,7 @@ #include #include "Common/Align.h" +#include "Common/Contains.h" #include "Common/GekkoDisassembler.h" #include "Common/StringUtil.h" @@ -253,7 +254,7 @@ Common::Debug::Threads PPCDebugInterface::GetThreads(const Core::CPUThreadGuard& const auto insert_threads = [&guard, &threads, &visited_addrs](u32 addr, auto get_next_addr) { while (addr != 0 && PowerPC::MMU::HostIsRAMAddress(guard, addr)) { - if (std::find(visited_addrs.begin(), visited_addrs.end(), addr) != visited_addrs.end()) + if (Common::Contains(visited_addrs, addr)) break; visited_addrs.push_back(addr); auto thread = std::make_unique(guard, addr); diff --git a/Source/Core/Core/WC24PatchEngine.cpp b/Source/Core/Core/WC24PatchEngine.cpp index f16efba192..9cf192e3e5 100644 --- a/Source/Core/Core/WC24PatchEngine.cpp +++ b/Source/Core/Core/WC24PatchEngine.cpp @@ -10,6 +10,7 @@ #include #include +#include "Common/Contains.h" #include "Common/IniFile.h" #include "Common/StringUtil.h" @@ -86,10 +87,7 @@ static void LoadPatchSection(const Common::IniFile& ini) static bool IsWC24Channel() { const auto& sconfig = SConfig::GetInstance(); - const auto found = - std::find(s_wc24_channels.begin(), s_wc24_channels.end(), sconfig.GetTitleID()); - - return found != s_wc24_channels.end(); + return Common::Contains(s_wc24_channels, sconfig.GetTitleID()); } static void LoadPatches() diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index 552b20cfb4..35b0b5670d 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -21,6 +21,7 @@ #include "Common/CPUDetect.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" +#include "Common/Contains.h" #include "Common/Crypto/SHA1.h" #include "Common/FileUtil.h" #include "Common/Hash.h" @@ -453,21 +454,18 @@ std::vector VolumeVerifier::CheckPartitions() types.emplace_back(*type); } - if (std::find(types.cbegin(), types.cend(), PARTITION_UPDATE) == types.cend()) + if (!Common::Contains(types, PARTITION_UPDATE)) AddProblem(Severity::Low, Common::GetStringT("The update partition is missing.")); - const bool has_data_partition = - std::find(types.cbegin(), types.cend(), PARTITION_DATA) != types.cend(); + const bool has_data_partition = Common::Contains(types, PARTITION_DATA); if (!m_is_datel && !has_data_partition) AddProblem(Severity::High, Common::GetStringT("The data partition is missing.")); - const bool has_channel_partition = - std::find(types.cbegin(), types.cend(), PARTITION_CHANNEL) != types.cend(); + const bool has_channel_partition = Common::Contains(types, PARTITION_CHANNEL); if (ShouldHaveChannelPartition() && !has_channel_partition) AddProblem(Severity::Medium, Common::GetStringT("The channel partition is missing.")); - const bool has_install_partition = - std::find(types.cbegin(), types.cend(), PARTITION_INSTALL) != types.cend(); + const bool has_install_partition = Common::Contains(types, PARTITION_INSTALL); if (ShouldHaveInstallPartition() && !has_install_partition) AddProblem(Severity::High, Common::GetStringT("The install partition is missing.")); diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index 053faaabd4..7824925396 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -43,6 +43,7 @@ #include #include "Common/CommonPaths.h" +#include "Common/Contains.h" #include "Common/FileUtil.h" #include "Core/Config/MainSettings.h" @@ -805,8 +806,7 @@ bool GameList::AddShortcutToDesktop() // Sanitize the string by removing all characters that cannot be used in NTFS file names std::erase_if(game_name, [](char ch) { static constexpr char illegal_characters[] = {'<', '>', ':', '\"', '/', '\\', '|', '?', '*'}; - return std::find(std::begin(illegal_characters), std::end(illegal_characters), ch) != - std::end(illegal_characters); + return Common::Contains(illegal_characters, ch); }); std::wstring desktop_path = std::wstring(desktop.get()) + UTF8ToTStr("\\" + game_name + ".lnk"); diff --git a/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp b/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp index 18ba1a2d3c..c78d038dfe 100644 --- a/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp @@ -16,6 +16,7 @@ #include #include +#include "Common/Contains.h" #include "Core/NetPlayClient.h" #include "Core/NetPlayServer.h" @@ -108,7 +109,7 @@ void ChunkedProgressDialog::show(const QString& title, const u64 data_size, for (const auto* player : client->GetPlayers()) { - if (std::find(players.begin(), players.end(), player->pid) == players.end()) + if (!Common::Contains(players, player->pid)) continue; m_progress_bars[player->pid] = new QProgressBar; diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index 938e892962..63bfae7a13 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -22,6 +22,7 @@ #include "AudioCommon/AudioCommon.h" #include "Common/Config/Config.h" +#include "Common/Contains.h" #include "Common/FileUtil.h" #include "Common/StringUtil.h" @@ -296,7 +297,7 @@ void Settings::AddPath(const QString& qpath) std::string path = qpath.toStdString(); std::vector paths = Config::GetIsoPaths(); - if (std::find(paths.begin(), paths.end(), path) != paths.end()) + if (Common::Contains(paths, path)) return; paths.emplace_back(path); diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp index b67974509b..b6e03e73a0 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp @@ -18,6 +18,7 @@ #include #include "Common/Assert.h" +#include "Common/Contains.h" #include "Common/Logging/Log.h" #include "Common/StringUtil.h" @@ -1132,8 +1133,7 @@ Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_notifySe for (ciface::Core::Device::Input* input : device->Inputs()) { - const std::string input_name = input->GetName(); - if (std::find(axis_names.begin(), axis_names.end(), input_name) != axis_names.end()) + if (Common::Contains(axis_names, input->GetName())) { auto casted_input = static_cast(input); casted_input->NotifyIsSuspended(static_cast(suspended)); diff --git a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp index f6d6a25239..117c3cc31c 100644 --- a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp +++ b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp @@ -10,6 +10,7 @@ #include #include "Common/CommonPaths.h" +#include "Common/Contains.h" #include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Common/IOFile.h" @@ -181,8 +182,7 @@ bool ResourcePack::Install(const std::string& path) bool provided_by_other_pack = false; for (const auto& pack : GetHigherPriorityPacks(*this)) { - if (std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) != - pack->GetTextures().end()) + if (Common::Contains(pack->GetTextures(), texture)) { provided_by_other_pack = true; break; @@ -246,9 +246,7 @@ bool ResourcePack::Uninstall(const std::string& path) // Check if a higher priority pack already provides a given texture, don't delete it for (const auto& pack : GetHigherPriorityPacks(*this)) { - if (::ResourcePack::IsInstalled(*pack) && - std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) != - pack->GetTextures().end()) + if (::ResourcePack::IsInstalled(*pack) && Common::Contains(pack->GetTextures(), texture)) { provided_by_other_pack = true; break; @@ -261,9 +259,7 @@ bool ResourcePack::Uninstall(const std::string& path) // Check if a lower priority pack provides a given texture - if so, install it. for (auto& pack : lower) { - if (::ResourcePack::IsInstalled(*pack) && - std::find(pack->GetTextures().rbegin(), pack->GetTextures().rend(), texture) != - pack->GetTextures().rend()) + if (::ResourcePack::IsInstalled(*pack) && Common::Contains(pack->GetTextures(), texture)) { pack->Install(path); diff --git a/Source/Core/UICommon/X11Utils.cpp b/Source/Core/UICommon/X11Utils.cpp index 219c897d9e..26f8a0ce09 100644 --- a/Source/Core/UICommon/X11Utils.cpp +++ b/Source/Core/UICommon/X11Utils.cpp @@ -14,6 +14,7 @@ #include +#include "Common/Contains.h" #include "Common/Logging/Log.h" #include "Common/StringUtil.h" #include "Core/Config/MainSettings.h" @@ -244,7 +245,7 @@ void XRRConfiguration::AddResolutions(std::vector& resos) std::string(screenResources->modes[k].name) + (interlaced ? "i" : ""); // Only add unique resolutions - if (std::find(resos.begin(), resos.end(), strRes) == resos.end()) + if (!Common::Contains(resos, strRes)) { resos.push_back(strRes); } diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp index 473cc06690..0001a9081d 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp @@ -7,6 +7,7 @@ #include #include +#include "Common/Contains.h" #include "Common/Logging/Log.h" #include "Common/VariantUtil.h" @@ -20,7 +21,7 @@ bool IsQualifier(std::string_view value) static constexpr std::array qualifiers = { "attribute", "const", "highp", "lowp", "mediump", "uniform", "varying", }; - return std::find(qualifiers.begin(), qualifiers.end(), value) != qualifiers.end(); + return Common::Contains(qualifiers, value); } bool IsBuiltInMacro(std::string_view value) @@ -28,7 +29,7 @@ bool IsBuiltInMacro(std::string_view value) static constexpr std::array built_in = { "__LINE__", "__FILE__", "__VERSION__", "GL_core_profile", "GL_compatibility_profile", }; - return std::find(built_in.begin(), built_in.end(), value) != built_in.end(); + return Common::Contains(built_in, value); } std::vector GlobalConflicts(std::string_view source) diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index b53cb3d2ed..21e5905d95 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -9,6 +9,7 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" +#include "Common/Contains.h" #include "Common/EnumMap.h" #include "Common/Logging/Log.h" #include "Common/MathUtil.h" @@ -585,8 +586,7 @@ void VertexManagerBase::Flush() const auto cache_entry = g_texture_cache->Load(TextureInfo::FromStage(i)); if (cache_entry) { - if (std::find(texture_names.begin(), texture_names.end(), - cache_entry->texture_info_name) == texture_names.end()) + if (!Common::Contains(texture_names, cache_entry->texture_info_name)) { texture_names.push_back(cache_entry->texture_info_name); texture_units.push_back(i); diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 8ca1f4ec63..9c73608b22 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -7,6 +7,7 @@ #include "Common/CPUDetect.h" #include "Common/CommonTypes.h" +#include "Common/Contains.h" #include "Common/StringUtil.h" #include "Core/CPUThreadConfigCallback.h" @@ -213,8 +214,7 @@ void VideoConfig::VerifyValidity() if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1)) iAdapter = 0; - if (std::find(backend_info.AAModes.begin(), backend_info.AAModes.end(), iMultisamples) == - backend_info.AAModes.end()) + if (!Common::Contains(backend_info.AAModes, iMultisamples)) iMultisamples = 1; if (stereo_mode != StereoMode::Off) From d92c68e1de481b509d92bbdd68f83c9a92f254aa Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sat, 21 Sep 2024 14:50:23 -0700 Subject: [PATCH 7/8] Simplify `std::find_if` with `Common::Contains` --- Source/Core/Core/State.cpp | 5 +-- Source/Core/Core/WiiUtils.cpp | 7 ++-- .../DolphinQt/Debugger/BreakpointWidget.cpp | 11 ++---- .../Core/VideoBackends/Vulkan/VKSwapChain.cpp | 14 ++----- .../VideoBackends/Vulkan/VulkanContext.cpp | 37 +++++++------------ 5 files changed, 25 insertions(+), 49 deletions(-) diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index f9964c0fa8..aac9d05221 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -24,6 +24,7 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" +#include "Common/Contains.h" #include "Common/Event.h" #include "Common/FileUtil.h" #include "Common/IOFile.h" @@ -261,9 +262,7 @@ static int GetEmptySlot(const std::vector& used_slots) { for (int i = 1; i <= (int)NUM_STATES; i++) { - const auto it = std::find_if(used_slots.begin(), used_slots.end(), - [i](const SlotWithTimestamp& slot) { return slot.slot == i; }); - if (it == used_slots.end()) + if (!Common::Contains(used_slots, i, &SlotWithTimestamp::slot)) return i; } return -1; diff --git a/Source/Core/Core/WiiUtils.cpp b/Source/Core/Core/WiiUtils.cpp index 054f3cf0c1..2c8b090e32 100644 --- a/Source/Core/Core/WiiUtils.cpp +++ b/Source/Core/Core/WiiUtils.cpp @@ -21,6 +21,7 @@ #include "Common/Align.h" #include "Common/Assert.h" #include "Common/CommonTypes.h" +#include "Common/Contains.h" #include "Common/EnumUtils.h" #include "Common/FileUtil.h" #include "Common/HttpRequest.h" @@ -590,10 +591,8 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_ const UpdateResult import_result = [&]() { for (const IOS::ES::Content& content : tmd.first.GetContents()) { - const bool is_already_installed = std::find_if(stored_contents.begin(), stored_contents.end(), - [&content](const auto& stored_content) { - return stored_content.id == content.id; - }) != stored_contents.end(); + const bool is_already_installed = + Common::Contains(stored_contents, content.id, &IOS::ES::Content::id); // Do skip what is already installed on the NAND. if (is_already_installed) diff --git a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp index 2737cb22ff..2c59e86f69 100644 --- a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp @@ -16,6 +16,7 @@ #include #include +#include "Common/Contains.h" #include "Common/FileUtil.h" #include "Common/IniFile.h" #include "Core/ConfigManager.h" @@ -522,10 +523,7 @@ void BreakpointWidget::OnContextMenu(const QPoint& pos) if (!is_memory_breakpoint) { const auto& inst_breakpoints = m_system.GetPowerPC().GetBreakPoints().GetBreakPoints(); - const auto bp_iter = - std::find_if(inst_breakpoints.begin(), inst_breakpoints.end(), - [bp_address](const auto& bp) { return bp.address == bp_address; }); - if (bp_iter == inst_breakpoints.end()) + if (!Common::Contains(inst_breakpoints, bp_address, &TBreakPoint::address)) return; menu->addAction(tr("Show in Code"), [this, bp_address] { emit ShowCode(bp_address); }); @@ -538,10 +536,7 @@ void BreakpointWidget::OnContextMenu(const QPoint& pos) else { const auto& memory_breakpoints = m_system.GetPowerPC().GetMemChecks().GetMemChecks(); - const auto mb_iter = - std::find_if(memory_breakpoints.begin(), memory_breakpoints.end(), - [bp_address](const auto& bp) { return bp.start_address == bp_address; }); - if (mb_iter == memory_breakpoints.end()) + if (!Common::Contains(memory_breakpoints, bp_address, &TMemCheck::start_address)) return; menu->addAction(tr("Show in Memory"), [this, bp_address] { emit ShowMemory(bp_address); }); diff --git a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp index bbe94944fb..f7260bdf0c 100644 --- a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp @@ -8,6 +8,7 @@ #include "Common/Assert.h" #include "Common/CommonFuncs.h" +#include "Common/Contains.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" @@ -243,31 +244,24 @@ bool SwapChain::SelectPresentMode() &mode_count, present_modes.data()); ASSERT(res == VK_SUCCESS); - // Checks if a particular mode is supported, if it is, returns that mode. - auto CheckForMode = [&present_modes](VkPresentModeKHR check_mode) { - auto it = std::find_if(present_modes.begin(), present_modes.end(), - [check_mode](VkPresentModeKHR mode) { return check_mode == mode; }); - return it != present_modes.end(); - }; - // If vsync is enabled, use VK_PRESENT_MODE_FIFO_KHR. // This check should not fail with conforming drivers, as the FIFO present mode is mandated by // the specification (VK_KHR_swapchain). In case it isn't though, fall through to any other mode. - if (m_vsync_enabled && CheckForMode(VK_PRESENT_MODE_FIFO_KHR)) + if (m_vsync_enabled && Common::Contains(present_modes, VK_PRESENT_MODE_FIFO_KHR)) { m_present_mode = VK_PRESENT_MODE_FIFO_KHR; return true; } // Prefer screen-tearing, if possible, for lowest latency. - if (CheckForMode(VK_PRESENT_MODE_IMMEDIATE_KHR)) + if (Common::Contains(present_modes, VK_PRESENT_MODE_IMMEDIATE_KHR)) { m_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR; return true; } // Use optimized-vsync above vsync. - if (CheckForMode(VK_PRESENT_MODE_MAILBOX_KHR)) + if (Common::Contains(present_modes, VK_PRESENT_MODE_MAILBOX_KHR)) { m_present_mode = VK_PRESENT_MODE_MAILBOX_KHR; return true; diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index ed3b709529..3640752231 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -9,6 +9,7 @@ #include "Common/Assert.h" #include "Common/CommonFuncs.h" +#include "Common/Contains.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" @@ -170,15 +171,12 @@ bool VulkanContext::CheckValidationLayerAvailablility() res = vkEnumerateInstanceLayerProperties(&layer_count, layer_list.data()); ASSERT(res == VK_SUCCESS); - bool supports_validation_layers = - std::find_if(layer_list.begin(), layer_list.end(), [](const auto& it) { - return strcmp(it.layerName, VALIDATION_LAYER_NAME) == 0; - }) != layer_list.end(); + bool supports_validation_layers = Common::Contains( + layer_list, std::string_view{VALIDATION_LAYER_NAME}, &VkLayerProperties::layerName); bool supports_debug_utils = - std::find_if(extension_list.begin(), extension_list.end(), [](const auto& it) { - return strcmp(it.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; - }) != extension_list.end(); + Common::Contains(extension_list, std::string_view{VK_EXT_DEBUG_UTILS_EXTENSION_NAME}, + &VkExtensionProperties::extensionName); if (!supports_debug_utils && supports_validation_layers) { @@ -197,9 +195,8 @@ bool VulkanContext::CheckValidationLayerAvailablility() extension_list.data()); ASSERT(res == VK_SUCCESS); supports_debug_utils = - std::find_if(extension_list.begin(), extension_list.end(), [](const auto& it) { - return strcmp(it.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; - }) != extension_list.end(); + Common::Contains(extension_list, std::string_view{VK_EXT_DEBUG_UTILS_EXTENSION_NAME}, + &VkExtensionProperties::extensionName); } // Check for both VK_EXT_debug_utils and VK_LAYER_KHRONOS_validation @@ -330,16 +327,10 @@ bool VulkanContext::SelectInstanceExtensions(std::vector* extension auto AddExtension = [&](const char* name, bool required) { bool extension_supported = - std::find_if(available_extension_list.begin(), available_extension_list.end(), - [&](const VkExtensionProperties& properties) { - return !strcmp(name, properties.extensionName); - }) != available_extension_list.end(); - extension_supported = - extension_supported || - std::find_if(validation_layer_extension_list.begin(), validation_layer_extension_list.end(), - [&](const VkExtensionProperties& properties) { - return !strcmp(name, properties.extensionName); - }) != validation_layer_extension_list.end(); + Common::Contains(available_extension_list, std::string_view{name}, + &VkExtensionProperties::extensionName) || + Common::Contains(validation_layer_extension_list, std::string_view{name}, + &VkExtensionProperties::extensionName); if (extension_supported) { @@ -648,10 +639,8 @@ bool VulkanContext::SelectDeviceExtensions(bool enable_surface) INFO_LOG_FMT(VIDEO, "Available extension: {}", extension_properties.extensionName); auto AddExtension = [&](const char* name, bool required) { - if (std::find_if(available_extension_list.begin(), available_extension_list.end(), - [&](const VkExtensionProperties& properties) { - return !strcmp(name, properties.extensionName); - }) != available_extension_list.end()) + if (Common::Contains(available_extension_list, std::string_view{name}, + &VkExtensionProperties::extensionName)) { INFO_LOG_FMT(VIDEO, "Enabling extension: {}", name); m_device_extensions.push_back(name); From 527841f1df2f4411a1f64ae439275cedcfc13bfa Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:41:25 -0700 Subject: [PATCH 8/8] Simplify `std::search` with `Common::ContainsSubrange` --- Source/Core/DiscIO/VolumeVerifier.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index 35b0b5670d..a4725cbbe2 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -144,11 +144,8 @@ RedumpVerifier::DownloadStatus RedumpVerifier::DownloadDatfile(const std::string if (File::Exists(output_path)) return DownloadStatus::FailButOldCacheAvailable; - const std::string system_not_available_message = "System \"" + system + "\" doesn't exist."; const bool system_not_available_match = - result->end() != std::search(result->begin(), result->end(), - system_not_available_message.begin(), - system_not_available_message.end()); + Common::ContainsSubrange(*result, "System \"" + system + "\" doesn't exist."); return system_not_available_match ? DownloadStatus::SystemNotAvailable : DownloadStatus::Fail; }