mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #13116 from mitaclaw/ranges-modernization-8-trivial-of
Ranges Algorithms Modernization - Of
This commit is contained in:
@@ -51,10 +51,9 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsModGroup_getMods(JN
|
||||
for (GraphicsModConfig& mod : mod_group->GetMods())
|
||||
{
|
||||
// If no group matches the mod's features, or if the mod has no features, skip it
|
||||
if (std::none_of(mod.m_features.begin(), mod.m_features.end(),
|
||||
[&groups](const GraphicsModFeatureConfig& feature) {
|
||||
return groups.contains(feature.m_group);
|
||||
}))
|
||||
if (std::ranges::none_of(mod.m_features, [&groups](const GraphicsModFeatureConfig& feature) {
|
||||
return groups.contains(feature.m_group);
|
||||
}))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ struct Elt
|
||||
{
|
||||
bool IsZero() const
|
||||
{
|
||||
return std::all_of(data.begin(), data.end(), [](u8 b) { return b == 0; });
|
||||
return std::ranges::all_of(data, [](u8 b) { return b == 0; });
|
||||
}
|
||||
|
||||
void MulX()
|
||||
|
||||
@@ -91,7 +91,7 @@ void MemoryPatches::DisablePatch(const Core::CPUThreadGuard& guard, std::size_t
|
||||
|
||||
bool MemoryPatches::HasEnabledPatch(u32 address) const
|
||||
{
|
||||
return std::any_of(m_patches.begin(), m_patches.end(), [address](const MemoryPatch& patch) {
|
||||
return std::ranges::any_of(m_patches, [address](const MemoryPatch& patch) {
|
||||
return patch.address == address && patch.is_enabled == MemoryPatch::State::Enabled;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ void Watches::DisableWatch(std::size_t index)
|
||||
|
||||
bool Watches::HasEnabledWatch(u32 address) const
|
||||
{
|
||||
return std::any_of(m_watches.begin(), m_watches.end(), [address](const auto& watch) {
|
||||
return std::ranges::any_of(m_watches, [address](const auto& watch) {
|
||||
return watch.address == address && watch.is_enabled == Watch::State::Enabled;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -729,7 +729,7 @@ static bool Unpack(const std::function<bool()>& cancelled, const std::string pat
|
||||
const bool is_path_traversal_attack =
|
||||
(childname.find("\\") != std::string_view::npos) ||
|
||||
(childname.find('/') != std::string_view::npos) ||
|
||||
std::all_of(childname.begin(), childname.end(), [](char c) { return c == '.'; });
|
||||
std::ranges::all_of(childname, [](char c) { return c == '.'; });
|
||||
if (is_path_traversal_attack)
|
||||
{
|
||||
ERROR_LOG_FMT(
|
||||
|
||||
@@ -41,7 +41,7 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
|
||||
// N.B. This avoids doing any copies
|
||||
auto ext_matches = [&native_exts](const fs::path& path) {
|
||||
const std::basic_string_view<fs::path::value_type> native_path = path.native();
|
||||
return std::any_of(native_exts.cbegin(), native_exts.cend(), [&native_path](const auto& ext) {
|
||||
return std::ranges::any_of(native_exts, [&native_path](const auto& ext) {
|
||||
const auto compare_len = ext.native().length();
|
||||
if (native_path.length() < compare_len)
|
||||
return false;
|
||||
|
||||
@@ -113,7 +113,7 @@ static bool IsIllegalCharacter(char c)
|
||||
std::string EscapeFileName(const std::string& filename)
|
||||
{
|
||||
// Prevent paths from containing special names like ., .., ..., ...., and so on
|
||||
if (std::all_of(filename.begin(), filename.end(), [](char c) { return c == '.'; }))
|
||||
if (std::ranges::all_of(filename, [](char c) { return c == '.'; }))
|
||||
return ReplaceAll(filename, ".", "__2e__");
|
||||
|
||||
// Escape all double underscores since we will use double underscores for our escape sequences
|
||||
@@ -170,8 +170,7 @@ std::string UnescapeFileName(const std::string& filename)
|
||||
|
||||
bool IsFileNameSafe(const std::string_view filename)
|
||||
{
|
||||
return !filename.empty() &&
|
||||
!std::all_of(filename.begin(), filename.end(), [](char c) { return c == '.'; }) &&
|
||||
std::none_of(filename.begin(), filename.end(), IsIllegalCharacter);
|
||||
return !filename.empty() && !std::ranges::all_of(filename, [](char c) { return c == '.'; }) &&
|
||||
std::ranges::none_of(filename, IsIllegalCharacter);
|
||||
}
|
||||
} // namespace Common
|
||||
|
||||
@@ -275,6 +275,21 @@ inline bool IsAlpha(char c)
|
||||
return std::isalpha(c, std::locale::classic());
|
||||
}
|
||||
|
||||
inline bool IsAlnum(char c)
|
||||
{
|
||||
return std::isalnum(c, std::locale::classic());
|
||||
}
|
||||
|
||||
inline bool IsUpper(char c)
|
||||
{
|
||||
return std::isupper(c, std::locale::classic());
|
||||
}
|
||||
|
||||
inline bool IsXDigit(char c)
|
||||
{
|
||||
return std::isxdigit(c /* no locale needed */) != 0;
|
||||
}
|
||||
|
||||
inline char ToLower(char ch)
|
||||
{
|
||||
return std::tolower(ch, std::locale::classic());
|
||||
|
||||
@@ -79,11 +79,9 @@ static DiscIO::Language ComputeDefaultLanguage()
|
||||
|
||||
static std::optional<std::string> TryParseCountryCode(const std::string& locale)
|
||||
{
|
||||
const auto is_upper = [](char c) { return std::isupper(c, std::locale::classic()); };
|
||||
|
||||
for (const std::string& part : SplitString(locale, '-'))
|
||||
{
|
||||
if (part.size() == 2 && is_upper(part[0]) && is_upper(part[1]))
|
||||
if (part.size() == 2 && Common::IsUpper(part[0]) && Common::IsUpper(part[1]))
|
||||
return part;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,9 +114,8 @@ public:
|
||||
for (const auto& value : section_map)
|
||||
{
|
||||
const Config::Location location{system.first, section_name, value.first};
|
||||
const bool load_disallowed =
|
||||
std::any_of(begin(s_setting_disallowed), end(s_setting_disallowed),
|
||||
[&location](const Config::Location* l) { return *l == location; });
|
||||
const bool load_disallowed = std::ranges::any_of(
|
||||
s_setting_disallowed, [&location](const auto* l) { return *l == location; });
|
||||
if (load_disallowed)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -27,9 +27,8 @@ bool IsSettingSaveable(const Config::Location& config_location)
|
||||
&Config::WIIMOTE_BB_SOURCE.GetLocation(),
|
||||
};
|
||||
|
||||
return std::any_of(begin(s_setting_saveable), end(s_setting_saveable),
|
||||
[&config_location](const Config::Location* location) {
|
||||
return *location == config_location;
|
||||
});
|
||||
return std::ranges::any_of(s_setting_saveable, [&config_location](const auto* location) {
|
||||
return *location == config_location;
|
||||
});
|
||||
}
|
||||
} // namespace ConfigLoaders
|
||||
|
||||
@@ -194,7 +194,7 @@ void DisplayMessage(std::string message, int time_in_ms)
|
||||
return;
|
||||
|
||||
// Actually displaying non-ASCII could cause things to go pear-shaped
|
||||
if (!std::all_of(message.begin(), message.end(), Common::IsPrintableCharacter))
|
||||
if (!std::ranges::all_of(message, Common::IsPrintableCharacter))
|
||||
return;
|
||||
|
||||
OSD::AddMessage(std::move(message), time_in_ms);
|
||||
|
||||
@@ -267,8 +267,8 @@ HitType CodeTrace::TraceLogic(const TraceOutput& current_instr, bool first_hit)
|
||||
|
||||
// Checks if the intstruction is a type that needs special handling.
|
||||
const auto CompareInstruction = [](std::string_view instruction, const auto& type_compare) {
|
||||
return std::any_of(type_compare.begin(), type_compare.end(),
|
||||
[&instruction](std::string_view s) { return instruction.starts_with(s); });
|
||||
return std::ranges::any_of(
|
||||
type_compare, [&instruction](std::string_view s) { return instruction.starts_with(s); });
|
||||
};
|
||||
|
||||
// Exclusions from updating tracking logic. mt operations are too complex and specialized.
|
||||
|
||||
@@ -101,8 +101,8 @@ std::pair<GCMemcardErrorCode, std::optional<GCMemcard>> GCMemcard::Open(std::str
|
||||
MBIT_SIZE_MEMORY_CARD_2043,
|
||||
}};
|
||||
|
||||
if (!std::any_of(valid_megabits.begin(), valid_megabits.end(),
|
||||
[filesize_megabits](u64 mbits) { return mbits == filesize_megabits; }))
|
||||
if (!std::ranges::any_of(valid_megabits,
|
||||
[filesize_megabits](u64 mbits) { return mbits == filesize_megabits; }))
|
||||
{
|
||||
error_code.Set(GCMemcardValidityIssues::INVALID_CARD_SIZE);
|
||||
return std::make_pair(error_code, std::nullopt);
|
||||
@@ -1296,8 +1296,8 @@ GCMemcardErrorCode Header::CheckForErrors(u16 card_size_mbits) const
|
||||
error_code.Set(GCMemcardValidityIssues::MISMATCHED_CARD_SIZE);
|
||||
|
||||
// unused areas, should always be filled with 0xFF
|
||||
if (std::any_of(m_unused_1.begin(), m_unused_1.end(), [](u8 val) { return val != 0xFF; }) ||
|
||||
std::any_of(m_unused_2.begin(), m_unused_2.end(), [](u8 val) { return val != 0xFF; }))
|
||||
if (std::ranges::any_of(m_unused_1, [](u8 val) { return val != 0xFF; }) ||
|
||||
std::ranges::any_of(m_unused_2, [](u8 val) { return val != 0xFF; }))
|
||||
{
|
||||
error_code.Set(GCMemcardValidityIssues::DATA_IN_UNUSED_AREA);
|
||||
}
|
||||
@@ -1361,7 +1361,7 @@ GCMemcardErrorCode Directory::CheckForErrors() const
|
||||
error_code.Set(GCMemcardValidityIssues::INVALID_CHECKSUM);
|
||||
|
||||
// unused area, should always be filled with 0xFF
|
||||
if (std::any_of(m_padding.begin(), m_padding.end(), [](u8 val) { return val != 0xFF; }))
|
||||
if (std::ranges::any_of(m_padding, [](u8 val) { return val != 0xFF; }))
|
||||
error_code.Set(GCMemcardValidityIssues::DATA_IN_UNUSED_AREA);
|
||||
|
||||
return error_code;
|
||||
|
||||
@@ -613,8 +613,7 @@ void WiimoteScanner::SetScanMode(WiimoteScanMode scan_mode)
|
||||
bool WiimoteScanner::IsReady() const
|
||||
{
|
||||
std::lock_guard lg(m_backends_mutex);
|
||||
return std::any_of(m_backends.begin(), m_backends.end(),
|
||||
[](const auto& backend) { return backend->IsReady(); });
|
||||
return std::ranges::any_of(m_backends, &WiimoteScannerBackend::IsReady);
|
||||
}
|
||||
|
||||
static void CheckForDisconnectedWiimotes()
|
||||
|
||||
@@ -98,8 +98,8 @@ bool IOCtlVRequest::HasNumberOfValidVectors(const size_t in_count, const size_t
|
||||
return false;
|
||||
|
||||
auto IsValidVector = [](const auto& vector) { return vector.size == 0 || vector.address != 0; };
|
||||
return std::all_of(in_vectors.begin(), in_vectors.end(), IsValidVector) &&
|
||||
std::all_of(io_vectors.begin(), io_vectors.end(), IsValidVector);
|
||||
return std::ranges::all_of(in_vectors, IsValidVector) &&
|
||||
std::ranges::all_of(io_vectors, IsValidVector);
|
||||
}
|
||||
|
||||
void IOCtlRequest::Log(std::string_view device_name, Common::Log::LogType type,
|
||||
|
||||
@@ -298,7 +298,7 @@ std::string TMDReader::GetGameID() const
|
||||
std::memcpy(game_id, m_bytes.data() + offsetof(TMDHeader, title_id) + 4, 4);
|
||||
std::memcpy(game_id + 4, m_bytes.data() + offsetof(TMDHeader, group_id), 2);
|
||||
|
||||
if (std::all_of(std::begin(game_id), std::end(game_id), Common::IsPrintableCharacter))
|
||||
if (std::ranges::all_of(game_id, Common::IsPrintableCharacter))
|
||||
return std::string(game_id, sizeof(game_id));
|
||||
|
||||
return fmt::format("{:016x}", GetTitleId());
|
||||
|
||||
@@ -79,8 +79,7 @@ static bool IsValidPartOfTitleID(const std::string& string)
|
||||
{
|
||||
if (string.length() != 8)
|
||||
return false;
|
||||
return std::all_of(string.begin(), string.end(),
|
||||
[](const auto character) { return std::isxdigit(character) != 0; });
|
||||
return std::ranges::all_of(string, Common::IsXDigit);
|
||||
}
|
||||
|
||||
static std::vector<u64> GetTitlesInTitleOrImport(FS::FileSystem* fs, const std::string& titles_dir)
|
||||
|
||||
@@ -464,7 +464,7 @@ static bool HasAllRequiredContents(Kernel& ios, const ES::TMDReader& tmd)
|
||||
const u64 title_id = tmd.GetTitleId();
|
||||
const std::vector<ES::Content> contents = tmd.GetContents();
|
||||
const ES::SharedContentMap shared_content_map{ios.GetFSCore()};
|
||||
return std::all_of(contents.cbegin(), contents.cend(), [&](const ES::Content& content) {
|
||||
return std::ranges::all_of(contents, [&](const ES::Content& content) {
|
||||
if (content.IsOptional())
|
||||
return true;
|
||||
|
||||
@@ -878,7 +878,7 @@ ReturnCode ESCore::DeleteSharedContent(const std::array<u8, 20>& sha1) const
|
||||
|
||||
// Check whether the shared content is used by a system title.
|
||||
const std::vector<u64> titles = GetInstalledTitles();
|
||||
const bool is_used_by_system_title = std::any_of(titles.begin(), titles.end(), [&](u64 id) {
|
||||
const bool is_used_by_system_title = std::ranges::any_of(titles, [&](u64 id) {
|
||||
if (!ES::IsTitleType(id, ES::TitleType::System))
|
||||
return false;
|
||||
|
||||
@@ -887,8 +887,8 @@ ReturnCode ESCore::DeleteSharedContent(const std::array<u8, 20>& sha1) const
|
||||
return true;
|
||||
|
||||
const auto contents = tmd.GetContents();
|
||||
return std::any_of(contents.begin(), contents.end(),
|
||||
[&sha1](const auto& content) { return content.sha1 == sha1; });
|
||||
return std::ranges::any_of(contents,
|
||||
[&sha1](const auto& content) { return content.sha1 == sha1; });
|
||||
});
|
||||
|
||||
// Any shared content used by a system title cannot be deleted.
|
||||
|
||||
@@ -26,7 +26,7 @@ bool IsValidNonRootPath(std::string_view path)
|
||||
bool IsValidFilename(std::string_view filename)
|
||||
{
|
||||
return filename.length() <= MaxFilenameLength &&
|
||||
!std::any_of(filename.begin(), filename.end(), [](char c) { return c == '/'; });
|
||||
!std::ranges::any_of(filename, [](char c) { return c == '/'; });
|
||||
}
|
||||
|
||||
SplitPathResult SplitPathAndBasename(std::string_view path)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user