This commit is contained in:
mitaclaw 2024-11-13 23:24:05 -05:00 committed by GitHub
commit 8836276cf9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 132 additions and 104 deletions

View File

@ -34,6 +34,7 @@ add_library(common
Config/Enums.h Config/Enums.h
Config/Layer.cpp Config/Layer.cpp
Config/Layer.h Config/Layer.h
Contains.h
CPUDetect.h CPUDetect.h
Crypto/AES.cpp Crypto/AES.cpp
Crypto/AES.h Crypto/AES.h

View File

@ -0,0 +1,61 @@
// Copyright 2024 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <algorithm>
#include <iterator>
namespace Common
{
struct ContainsFn
{
template <std::input_iterator I, std::sentinel_for<I> S, class T, class Proj = std::identity>
requires std::indirect_binary_predicate < std::ranges::equal_to, std::projected<I, Proj>,
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 <std::ranges::input_range R, class T, class Proj = std::identity>
requires std::indirect_binary_predicate < std::ranges::equal_to,
std::projected<std::ranges::iterator_t<R>, 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 <std::forward_iterator I1, std::sentinel_for<I1> S1, std::forward_iterator I2,
std::sentinel_for<I2> S2, class Pred = std::ranges::equal_to,
class Proj1 = std::identity, class Proj2 = std::identity>
requires std::indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
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 <std::ranges::forward_range R1, std::ranges::forward_range R2,
class Pred = std::ranges::equal_to, class Proj1 = std::identity,
class Proj2 = std::identity>
requires std::indirectly_comparable<std::ranges::iterator_t<R1>, std::ranges::iterator_t<R2>,
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

View File

@ -11,6 +11,7 @@
#include <fmt/ranges.h> #include <fmt/ranges.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Contains.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -105,9 +106,8 @@ bool IsTitlePath(const std::string& path, std::optional<FromWhichRoot> from, u64
static bool IsIllegalCharacter(char c) static bool IsIllegalCharacter(char c)
{ {
static constexpr auto illegal_chars = {'\"', '*', '/', ':', '<', '>', '?', '\\', '|', '\x7f'}; static constexpr char illegal_chars[] = {'\"', '*', '/', ':', '<', '>', '?', '\\', '|', '\x7f'};
return static_cast<unsigned char>(c) <= 0x1F || return static_cast<unsigned char>(c) <= 0x1F || Common::Contains(illegal_chars, c);
std::find(illegal_chars.begin(), illegal_chars.end(), c) != illegal_chars.end();
} }
std::string EscapeFileName(const std::string& filename) std::string EscapeFileName(const std::string& filename)

View File

@ -17,6 +17,7 @@
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Contains.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/Host.h" #include "Core/Host.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
@ -38,17 +39,13 @@ static std::optional<DiscIO::Language> TryParseLanguage(const std::string& local
// Special handling of Chinese due to its two writing systems // Special handling of Chinese due to its two writing systems
if (split_locale[0] == "zh") if (split_locale[0] == "zh")
{ {
const auto locale_contains = [&split_locale](std::string_view str) { if (Common::Contains(split_locale, "Hans"))
return std::find(split_locale.cbegin(), split_locale.cend(), str) != split_locale.cend();
};
if (locale_contains("Hans"))
return DiscIO::Language::SimplifiedChinese; return DiscIO::Language::SimplifiedChinese;
if (locale_contains("Hant")) if (Common::Contains(split_locale, "Hant"))
return DiscIO::Language::TraditionalChinese; return DiscIO::Language::TraditionalChinese;
// Mainland China and Singapore use simplified characters // 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; return DiscIO::Language::SimplifiedChinese;
else else
return DiscIO::Language::TraditionalChinese; return DiscIO::Language::TraditionalChinese;

View File

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include "Common/Contains.h"
#include "Core/Config/WiimoteSettings.h" #include "Core/Config/WiimoteSettings.h"
namespace ConfigLoaders 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, static constexpr std::array systems_not_saveable = {Config::System::GCPad, Config::System::WiiPad,
Config::System::GCKeyboard}; Config::System::GCKeyboard};
if (std::find(begin(systems_not_saveable), end(systems_not_saveable), config_location.system) == if (!Common::Contains(systems_not_saveable, config_location.system))
end(systems_not_saveable))
{ {
return true; return true;
} }

View File

@ -7,6 +7,7 @@
#include <chrono> #include <chrono>
#include <regex> #include <regex>
#include "Common/Contains.h"
#include "Common/Event.h" #include "Common/Event.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/Debugger/PPCDebugInterface.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. // The reg_itr will be used later for erasing.
auto reg_itr = std::ranges::find(m_reg_autotrack, instr.reg0); auto reg_itr = std::ranges::find(m_reg_autotrack, instr.reg0);
const bool match_reg123 = const bool match_reg123 =
(!instr.reg1.empty() && std::find(m_reg_autotrack.begin(), m_reg_autotrack.end(), (!instr.reg1.empty() && Common::Contains(m_reg_autotrack, instr.reg1)) ||
instr.reg1) != m_reg_autotrack.end()) || (!instr.reg2.empty() && Common::Contains(m_reg_autotrack, instr.reg2)) ||
(!instr.reg2.empty() && std::find(m_reg_autotrack.begin(), m_reg_autotrack.end(), (!instr.reg3.empty() && Common::Contains(m_reg_autotrack, instr.reg3));
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());
const bool match_reg0 = reg_itr != m_reg_autotrack.end(); const bool match_reg0 = reg_itr != m_reg_autotrack.end();
if (!match_reg0 && !match_reg123 && !mem_hit) if (!match_reg0 && !match_reg123 && !mem_hit)

View File

@ -13,6 +13,7 @@
#include <fmt/format.h> #include <fmt/format.h>
#include "Common/Align.h" #include "Common/Align.h"
#include "Common/Contains.h"
#include "Common/GekkoDisassembler.h" #include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.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) { const auto insert_threads = [&guard, &threads, &visited_addrs](u32 addr, auto get_next_addr) {
while (addr != 0 && PowerPC::MMU::HostIsRAMAddress(guard, 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; break;
visited_addrs.push_back(addr); visited_addrs.push_back(addr);
auto thread = std::make_unique<Core::Debug::OSThreadView>(guard, addr); auto thread = std::make_unique<Core::Debug::OSThreadView>(guard, addr);

View File

@ -24,6 +24,7 @@
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Contains.h"
#include "Common/Event.h" #include "Common/Event.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/IOFile.h" #include "Common/IOFile.h"
@ -261,9 +262,7 @@ static int GetEmptySlot(const std::vector<SlotWithTimestamp>& used_slots)
{ {
for (int i = 1; i <= (int)NUM_STATES; i++) for (int i = 1; i <= (int)NUM_STATES; i++)
{ {
const auto it = std::find_if(used_slots.begin(), used_slots.end(), if (!Common::Contains(used_slots, i, &SlotWithTimestamp::slot))
[i](const SlotWithTimestamp& slot) { return slot.slot == i; });
if (it == used_slots.end())
return i; return i;
} }
return -1; return -1;

View File

@ -10,6 +10,7 @@
#include <array> #include <array>
#include <fmt/format.h> #include <fmt/format.h>
#include "Common/Contains.h"
#include "Common/IniFile.h" #include "Common/IniFile.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -86,10 +87,7 @@ static void LoadPatchSection(const Common::IniFile& ini)
static bool IsWC24Channel() static bool IsWC24Channel()
{ {
const auto& sconfig = SConfig::GetInstance(); const auto& sconfig = SConfig::GetInstance();
const auto found = return Common::Contains(s_wc24_channels, sconfig.GetTitleID());
std::find(s_wc24_channels.begin(), s_wc24_channels.end(), sconfig.GetTitleID());
return found != s_wc24_channels.end();
} }
static void LoadPatches() static void LoadPatches()

View File

@ -21,6 +21,7 @@
#include "Common/Align.h" #include "Common/Align.h"
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Contains.h"
#include "Common/EnumUtils.h" #include "Common/EnumUtils.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/HttpRequest.h" #include "Common/HttpRequest.h"
@ -591,10 +592,8 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
const UpdateResult import_result = [&]() { const UpdateResult import_result = [&]() {
for (const IOS::ES::Content& content : tmd.first.GetContents()) for (const IOS::ES::Content& content : tmd.first.GetContents())
{ {
const bool is_already_installed = std::find_if(stored_contents.begin(), stored_contents.end(), const bool is_already_installed =
[&content](const auto& stored_content) { Common::Contains(stored_contents, content.id, &IOS::ES::Content::id);
return stored_content.id == content.id;
}) != stored_contents.end();
// Do skip what is already installed on the NAND. // Do skip what is already installed on the NAND.
if (is_already_installed) if (is_already_installed)

View File

@ -21,6 +21,7 @@
#include "Common/CPUDetect.h" #include "Common/CPUDetect.h"
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Contains.h"
#include "Common/Crypto/SHA1.h" #include "Common/Crypto/SHA1.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/Hash.h" #include "Common/Hash.h"
@ -143,11 +144,8 @@ RedumpVerifier::DownloadStatus RedumpVerifier::DownloadDatfile(const std::string
if (File::Exists(output_path)) if (File::Exists(output_path))
return DownloadStatus::FailButOldCacheAvailable; return DownloadStatus::FailButOldCacheAvailable;
const std::string system_not_available_message = "System \"" + system + "\" doesn't exist.";
const bool system_not_available_match = const bool system_not_available_match =
result->end() != std::search(result->begin(), result->end(), Common::ContainsSubrange(*result, "System \"" + system + "\" doesn't exist.");
system_not_available_message.begin(),
system_not_available_message.end());
return system_not_available_match ? DownloadStatus::SystemNotAvailable : DownloadStatus::Fail; return system_not_available_match ? DownloadStatus::SystemNotAvailable : DownloadStatus::Fail;
} }
@ -453,21 +451,18 @@ std::vector<Partition> VolumeVerifier::CheckPartitions()
types.emplace_back(*type); 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.")); AddProblem(Severity::Low, Common::GetStringT("The update partition is missing."));
const bool has_data_partition = const bool has_data_partition = Common::Contains(types, PARTITION_DATA);
std::find(types.cbegin(), types.cend(), PARTITION_DATA) != types.cend();
if (!m_is_datel && !has_data_partition) if (!m_is_datel && !has_data_partition)
AddProblem(Severity::High, Common::GetStringT("The data partition is missing.")); AddProblem(Severity::High, Common::GetStringT("The data partition is missing."));
const bool has_channel_partition = const bool has_channel_partition = Common::Contains(types, PARTITION_CHANNEL);
std::find(types.cbegin(), types.cend(), PARTITION_CHANNEL) != types.cend();
if (ShouldHaveChannelPartition() && !has_channel_partition) if (ShouldHaveChannelPartition() && !has_channel_partition)
AddProblem(Severity::Medium, Common::GetStringT("The channel partition is missing.")); AddProblem(Severity::Medium, Common::GetStringT("The channel partition is missing."));
const bool has_install_partition = const bool has_install_partition = Common::Contains(types, PARTITION_INSTALL);
std::find(types.cbegin(), types.cend(), PARTITION_INSTALL) != types.cend();
if (ShouldHaveInstallPartition() && !has_install_partition) if (ShouldHaveInstallPartition() && !has_install_partition)
AddProblem(Severity::High, Common::GetStringT("The install partition is missing.")); AddProblem(Severity::High, Common::GetStringT("The install partition is missing."));

View File

@ -38,6 +38,7 @@
<ClInclude Include="Common\Config\ConfigInfo.h" /> <ClInclude Include="Common\Config\ConfigInfo.h" />
<ClInclude Include="Common\Config\Enums.h" /> <ClInclude Include="Common\Config\Enums.h" />
<ClInclude Include="Common\Config\Layer.h" /> <ClInclude Include="Common\Config\Layer.h" />
<ClInclude Include="Common\Contains.h" />
<ClInclude Include="Common\CPUDetect.h" /> <ClInclude Include="Common\CPUDetect.h" />
<ClInclude Include="Common\Crypto\AES.h" /> <ClInclude Include="Common\Crypto\AES.h" />
<ClInclude Include="Common\Crypto\bn.h" /> <ClInclude Include="Common\Crypto\bn.h" />

View File

@ -16,6 +16,7 @@
#include <QToolBar> #include <QToolBar>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "Common/Contains.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/IniFile.h" #include "Common/IniFile.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
@ -522,10 +523,7 @@ void BreakpointWidget::OnContextMenu(const QPoint& pos)
if (!is_memory_breakpoint) if (!is_memory_breakpoint)
{ {
const auto& inst_breakpoints = m_system.GetPowerPC().GetBreakPoints().GetBreakPoints(); const auto& inst_breakpoints = m_system.GetPowerPC().GetBreakPoints().GetBreakPoints();
const auto bp_iter = if (!Common::Contains(inst_breakpoints, bp_address, &TBreakPoint::address))
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())
return; return;
menu->addAction(tr("Show in Code"), [this, bp_address] { emit ShowCode(bp_address); }); menu->addAction(tr("Show in Code"), [this, bp_address] { emit ShowCode(bp_address); });
@ -538,10 +536,7 @@ void BreakpointWidget::OnContextMenu(const QPoint& pos)
else else
{ {
const auto& memory_breakpoints = m_system.GetPowerPC().GetMemChecks().GetMemChecks(); const auto& memory_breakpoints = m_system.GetPowerPC().GetMemChecks().GetMemChecks();
const auto mb_iter = if (!Common::Contains(memory_breakpoints, bp_address, &TMemCheck::start_address))
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())
return; return;
menu->addAction(tr("Show in Memory"), [this, bp_address] { emit ShowMemory(bp_address); }); menu->addAction(tr("Show in Memory"), [this, bp_address] { emit ShowMemory(bp_address); });

View File

@ -43,6 +43,7 @@
#include <QUrl> #include <QUrl>
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/Contains.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Core/Config/MainSettings.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 // Sanitize the string by removing all characters that cannot be used in NTFS file names
std::erase_if(game_name, [](char ch) { std::erase_if(game_name, [](char ch) {
static constexpr char illegal_characters[] = {'<', '>', ':', '\"', '/', '\\', '|', '?', '*'}; static constexpr char illegal_characters[] = {'<', '>', ':', '\"', '/', '\\', '|', '?', '*'};
return std::find(std::begin(illegal_characters), std::end(illegal_characters), ch) != return Common::Contains(illegal_characters, ch);
std::end(illegal_characters);
}); });
std::wstring desktop_path = std::wstring(desktop.get()) + UTF8ToTStr("\\" + game_name + ".lnk"); std::wstring desktop_path = std::wstring(desktop.get()) + UTF8ToTStr("\\" + game_name + ".lnk");

View File

@ -16,6 +16,7 @@
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "Common/Contains.h"
#include "Core/NetPlayClient.h" #include "Core/NetPlayClient.h"
#include "Core/NetPlayServer.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()) for (const auto* player : client->GetPlayers())
{ {
if (std::find(players.begin(), players.end(), player->pid) == players.end()) if (!Common::Contains(players, player->pid))
continue; continue;
m_progress_bars[player->pid] = new QProgressBar; m_progress_bars[player->pid] = new QProgressBar;

View File

@ -22,6 +22,7 @@
#include "AudioCommon/AudioCommon.h" #include "AudioCommon/AudioCommon.h"
#include "Common/Config/Config.h" #include "Common/Config/Config.h"
#include "Common/Contains.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -296,7 +297,7 @@ void Settings::AddPath(const QString& qpath)
std::string path = qpath.toStdString(); std::string path = qpath.toStdString();
std::vector<std::string> paths = Config::GetIsoPaths(); std::vector<std::string> paths = Config::GetIsoPaths();
if (std::find(paths.begin(), paths.end(), path) != paths.end()) if (Common::Contains(paths, path))
return; return;
paths.emplace_back(path); paths.emplace_back(path);

View File

@ -18,6 +18,7 @@
#include <jni.h> #include <jni.h>
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/Contains.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/StringUtil.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()) for (ciface::Core::Device::Input* input : device->Inputs())
{ {
const std::string input_name = input->GetName(); if (Common::Contains(axis_names, input->GetName()))
if (std::find(axis_names.begin(), axis_names.end(), input_name) != axis_names.end())
{ {
auto casted_input = static_cast<ciface::Android::AndroidSensorAxis*>(input); auto casted_input = static_cast<ciface::Android::AndroidSensorAxis*>(input);
casted_input->NotifyIsSuspended(static_cast<bool>(suspended)); casted_input->NotifyIsSuspended(static_cast<bool>(suspended));

View File

@ -10,6 +10,7 @@
#include <mz_os.h> #include <mz_os.h>
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/Contains.h"
#include "Common/FileSearch.h" #include "Common/FileSearch.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/IOFile.h" #include "Common/IOFile.h"
@ -181,8 +182,7 @@ bool ResourcePack::Install(const std::string& path)
bool provided_by_other_pack = false; bool provided_by_other_pack = false;
for (const auto& pack : GetHigherPriorityPacks(*this)) for (const auto& pack : GetHigherPriorityPacks(*this))
{ {
if (std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) != if (Common::Contains(pack->GetTextures(), texture))
pack->GetTextures().end())
{ {
provided_by_other_pack = true; provided_by_other_pack = true;
break; 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 // Check if a higher priority pack already provides a given texture, don't delete it
for (const auto& pack : GetHigherPriorityPacks(*this)) for (const auto& pack : GetHigherPriorityPacks(*this))
{ {
if (::ResourcePack::IsInstalled(*pack) && if (::ResourcePack::IsInstalled(*pack) && Common::Contains(pack->GetTextures(), texture))
std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) !=
pack->GetTextures().end())
{ {
provided_by_other_pack = true; provided_by_other_pack = true;
break; 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. // Check if a lower priority pack provides a given texture - if so, install it.
for (auto& pack : lower) for (auto& pack : lower)
{ {
if (::ResourcePack::IsInstalled(*pack) && if (::ResourcePack::IsInstalled(*pack) && Common::Contains(pack->GetTextures(), texture))
std::find(pack->GetTextures().rbegin(), pack->GetTextures().rend(), texture) !=
pack->GetTextures().rend())
{ {
pack->Install(path); pack->Install(path);

View File

@ -14,6 +14,7 @@
#include <fmt/format.h> #include <fmt/format.h>
#include "Common/Contains.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
@ -244,7 +245,7 @@ void XRRConfiguration::AddResolutions(std::vector<std::string>& resos)
std::string(screenResources->modes[k].name) + std::string(screenResources->modes[k].name) +
(interlaced ? "i" : ""); (interlaced ? "i" : "");
// Only add unique resolutions // Only add unique resolutions
if (std::find(resos.begin(), resos.end(), strRes) == resos.end()) if (!Common::Contains(resos, strRes))
{ {
resos.push_back(strRes); resos.push_back(strRes);
} }

View File

@ -8,6 +8,7 @@
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/CommonFuncs.h" #include "Common/CommonFuncs.h"
#include "Common/Contains.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
@ -241,31 +242,24 @@ bool SwapChain::SelectPresentMode()
&mode_count, present_modes.data()); &mode_count, present_modes.data());
ASSERT(res == VK_SUCCESS); 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. // 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 // 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. // 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; m_present_mode = VK_PRESENT_MODE_FIFO_KHR;
return true; return true;
} }
// Prefer screen-tearing, if possible, for lowest latency. // 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; m_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
return true; return true;
} }
// Use optimized-vsync above vsync. // 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; m_present_mode = VK_PRESENT_MODE_MAILBOX_KHR;
return true; return true;

View File

@ -9,6 +9,7 @@
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/CommonFuncs.h" #include "Common/CommonFuncs.h"
#include "Common/Contains.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -170,15 +171,12 @@ bool VulkanContext::CheckValidationLayerAvailablility()
res = vkEnumerateInstanceLayerProperties(&layer_count, layer_list.data()); res = vkEnumerateInstanceLayerProperties(&layer_count, layer_list.data());
ASSERT(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
bool supports_validation_layers = bool supports_validation_layers = Common::Contains(
std::find_if(layer_list.begin(), layer_list.end(), [](const auto& it) { layer_list, std::string_view{VALIDATION_LAYER_NAME}, &VkLayerProperties::layerName);
return strcmp(it.layerName, VALIDATION_LAYER_NAME) == 0;
}) != layer_list.end();
bool supports_debug_utils = bool supports_debug_utils =
std::find_if(extension_list.begin(), extension_list.end(), [](const auto& it) { Common::Contains(extension_list, std::string_view{VK_EXT_DEBUG_UTILS_EXTENSION_NAME},
return strcmp(it.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; &VkExtensionProperties::extensionName);
}) != extension_list.end();
if (!supports_debug_utils && supports_validation_layers) if (!supports_debug_utils && supports_validation_layers)
{ {
@ -197,9 +195,8 @@ bool VulkanContext::CheckValidationLayerAvailablility()
extension_list.data()); extension_list.data());
ASSERT(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
supports_debug_utils = supports_debug_utils =
std::find_if(extension_list.begin(), extension_list.end(), [](const auto& it) { Common::Contains(extension_list, std::string_view{VK_EXT_DEBUG_UTILS_EXTENSION_NAME},
return strcmp(it.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; &VkExtensionProperties::extensionName);
}) != extension_list.end();
} }
// Check for both VK_EXT_debug_utils and VK_LAYER_KHRONOS_validation // Check for both VK_EXT_debug_utils and VK_LAYER_KHRONOS_validation
@ -330,16 +327,10 @@ bool VulkanContext::SelectInstanceExtensions(std::vector<const char*>* extension
auto AddExtension = [&](const char* name, bool required) { auto AddExtension = [&](const char* name, bool required) {
bool extension_supported = bool extension_supported =
std::find_if(available_extension_list.begin(), available_extension_list.end(), Common::Contains(available_extension_list, std::string_view{name},
[&](const VkExtensionProperties& properties) { &VkExtensionProperties::extensionName) ||
return !strcmp(name, properties.extensionName); Common::Contains(validation_layer_extension_list, std::string_view{name},
}) != available_extension_list.end(); &VkExtensionProperties::extensionName);
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();
if (extension_supported) if (extension_supported)
{ {
@ -648,10 +639,8 @@ bool VulkanContext::SelectDeviceExtensions(bool enable_surface)
INFO_LOG_FMT(VIDEO, "Available extension: {}", extension_properties.extensionName); INFO_LOG_FMT(VIDEO, "Available extension: {}", extension_properties.extensionName);
auto AddExtension = [&](const char* name, bool required) { auto AddExtension = [&](const char* name, bool required) {
if (std::find_if(available_extension_list.begin(), available_extension_list.end(), if (Common::Contains(available_extension_list, std::string_view{name},
[&](const VkExtensionProperties& properties) { &VkExtensionProperties::extensionName))
return !strcmp(name, properties.extensionName);
}) != available_extension_list.end())
{ {
INFO_LOG_FMT(VIDEO, "Enabling extension: {}", name); INFO_LOG_FMT(VIDEO, "Enabling extension: {}", name);
m_device_extensions.push_back(name); m_device_extensions.push_back(name);

View File

@ -7,6 +7,7 @@
#include <array> #include <array>
#include <variant> #include <variant>
#include "Common/Contains.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/VariantUtil.h" #include "Common/VariantUtil.h"
@ -20,7 +21,7 @@ bool IsQualifier(std::string_view value)
static constexpr std::array<std::string_view, 7> qualifiers = { static constexpr std::array<std::string_view, 7> qualifiers = {
"attribute", "const", "highp", "lowp", "mediump", "uniform", "varying", "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) bool IsBuiltInMacro(std::string_view value)
@ -28,7 +29,7 @@ bool IsBuiltInMacro(std::string_view value)
static constexpr std::array<std::string_view, 5> built_in = { static constexpr std::array<std::string_view, 5> built_in = {
"__LINE__", "__FILE__", "__VERSION__", "GL_core_profile", "GL_compatibility_profile", "__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<std::string> GlobalConflicts(std::string_view source) std::vector<std::string> GlobalConflicts(std::string_view source)

View File

@ -9,6 +9,7 @@
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Contains.h"
#include "Common/EnumMap.h" #include "Common/EnumMap.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
@ -585,8 +586,7 @@ void VertexManagerBase::Flush()
const auto cache_entry = g_texture_cache->Load(TextureInfo::FromStage(i)); const auto cache_entry = g_texture_cache->Load(TextureInfo::FromStage(i));
if (cache_entry) if (cache_entry)
{ {
if (std::find(texture_names.begin(), texture_names.end(), if (!Common::Contains(texture_names, cache_entry->texture_info_name))
cache_entry->texture_info_name) == texture_names.end())
{ {
texture_names.push_back(cache_entry->texture_info_name); texture_names.push_back(cache_entry->texture_info_name);
texture_units.push_back(i); texture_units.push_back(i);

View File

@ -7,6 +7,7 @@
#include "Common/CPUDetect.h" #include "Common/CPUDetect.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Contains.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/CPUThreadConfigCallback.h" #include "Core/CPUThreadConfigCallback.h"
@ -213,8 +214,7 @@ void VideoConfig::VerifyValidity()
if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1)) if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1))
iAdapter = 0; iAdapter = 0;
if (std::find(backend_info.AAModes.begin(), backend_info.AAModes.end(), iMultisamples) == if (!Common::Contains(backend_info.AAModes, iMultisamples))
backend_info.AAModes.end())
iMultisamples = 1; iMultisamples = 1;
if (stereo_mode != StereoMode::Off) if (stereo_mode != StereoMode::Off)