Merge pull request #13096 from mitaclaw/ranges-modernization-7-rewrite
Ranges Algorithms Modernization - Rewrite
This commit is contained in:
commit
96c9591b99
|
@ -47,7 +47,7 @@ private:
|
||||||
std::array<uint32_t, 36 + sizeof...(ExtraMatches)> _conns;
|
std::array<uint32_t, 36 + sizeof...(ExtraMatches)> _conns;
|
||||||
std::optional<V> _val;
|
std::optional<V> _val;
|
||||||
|
|
||||||
TrieEntry() { std::fill(_conns.begin(), _conns.end(), INVALID_CONN); }
|
TrieEntry() { _conns.fill(INVALID_CONN); }
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr size_t IndexOf(char c) const
|
constexpr size_t IndexOf(char c) const
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -575,7 +576,7 @@ SharedContentMap::GetFilenameFromSHA1(const std::array<u8, 20>& sha1) const
|
||||||
if (it == m_entries.end())
|
if (it == m_entries.end())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const std::string id_string(it->id.begin(), it->id.end());
|
const std::string_view id_string(reinterpret_cast<const char*>(it->id.data()), it->id.size());
|
||||||
return fmt::format("/shared1/{}.app", id_string);
|
return fmt::format("/shared1/{}.app", id_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,20 +592,22 @@ std::vector<std::array<u8, 20>> SharedContentMap::GetHashes() const
|
||||||
|
|
||||||
std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
||||||
{
|
{
|
||||||
auto filename = GetFilenameFromSHA1(sha1);
|
if (auto filename = GetFilenameFromSHA1(sha1))
|
||||||
if (filename)
|
return *std::move(filename);
|
||||||
return *filename;
|
|
||||||
|
|
||||||
const std::string id = fmt::format("{:08x}", m_last_id);
|
Entry& entry = m_entries.emplace_back();
|
||||||
Entry entry;
|
static_assert(sizeof(m_last_id) == 4,
|
||||||
std::copy(id.cbegin(), id.cend(), entry.id.begin());
|
"'m_last_id' must be represented by 8 characters when formatted in hexadecimal.");
|
||||||
|
static_assert(std::tuple_size_v<decltype(entry.id)> == sizeof(m_last_id) * 2,
|
||||||
|
"'entry.id' must be a std::array capable of storing every nibble of 'm_last_id'.");
|
||||||
|
fmt::format_to(entry.id.data(), "{:08x}", m_last_id);
|
||||||
entry.sha1 = sha1;
|
entry.sha1 = sha1;
|
||||||
m_entries.push_back(entry);
|
|
||||||
|
|
||||||
WriteEntries();
|
WriteEntries();
|
||||||
filename = fmt::format("/shared1/{}.app", id);
|
|
||||||
m_last_id++;
|
m_last_id++;
|
||||||
return *filename;
|
|
||||||
|
const std::string_view id_string(reinterpret_cast<const char*>(entry.id.data()), entry.id.size());
|
||||||
|
return fmt::format("/shared1/{}.app", id_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SharedContentMap::DeleteSharedContent(const std::array<u8, 20>& sha1)
|
bool SharedContentMap::DeleteSharedContent(const std::array<u8, 20>& sha1)
|
||||||
|
|
|
@ -140,20 +140,14 @@ void ARCodeWidget::SortAlphabetically()
|
||||||
|
|
||||||
void ARCodeWidget::SortEnabledCodesFirst()
|
void ARCodeWidget::SortEnabledCodesFirst()
|
||||||
{
|
{
|
||||||
std::stable_sort(m_ar_codes.begin(), m_ar_codes.end(), [](const auto& a, const auto& b) {
|
std::ranges::stable_partition(m_ar_codes, std::identity{}, &ActionReplay::ARCode::enabled);
|
||||||
return a.enabled && a.enabled != b.enabled;
|
|
||||||
});
|
|
||||||
|
|
||||||
UpdateList();
|
UpdateList();
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARCodeWidget::SortDisabledCodesFirst()
|
void ARCodeWidget::SortDisabledCodesFirst()
|
||||||
{
|
{
|
||||||
std::stable_sort(m_ar_codes.begin(), m_ar_codes.end(), [](const auto& a, const auto& b) {
|
std::ranges::stable_partition(m_ar_codes, std::logical_not{}, &ActionReplay::ARCode::enabled);
|
||||||
return !a.enabled && a.enabled != b.enabled;
|
|
||||||
});
|
|
||||||
|
|
||||||
UpdateList();
|
UpdateList();
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,20 +314,14 @@ void GeckoCodeWidget::SortAlphabetically()
|
||||||
|
|
||||||
void GeckoCodeWidget::SortEnabledCodesFirst()
|
void GeckoCodeWidget::SortEnabledCodesFirst()
|
||||||
{
|
{
|
||||||
std::stable_sort(m_gecko_codes.begin(), m_gecko_codes.end(), [](const auto& a, const auto& b) {
|
std::ranges::stable_partition(m_gecko_codes, std::identity{}, &Gecko::GeckoCode::enabled);
|
||||||
return a.enabled && a.enabled != b.enabled;
|
|
||||||
});
|
|
||||||
|
|
||||||
UpdateList();
|
UpdateList();
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::SortDisabledCodesFirst()
|
void GeckoCodeWidget::SortDisabledCodesFirst()
|
||||||
{
|
{
|
||||||
std::stable_sort(m_gecko_codes.begin(), m_gecko_codes.end(), [](const auto& a, const auto& b) {
|
std::ranges::stable_partition(m_gecko_codes, std::logical_not{}, &Gecko::GeckoCode::enabled);
|
||||||
return !a.enabled && a.enabled != b.enabled;
|
|
||||||
});
|
|
||||||
|
|
||||||
UpdateList();
|
UpdateList();
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <fmt/ranges.h>
|
#include <fmt/ranges.h>
|
||||||
|
@ -284,11 +285,10 @@ void ReshapableInput::SaveConfig(Common::IniFile::Section* section,
|
||||||
50.0);
|
50.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> save_data(m_calibration.size());
|
const std::ranges::transform_view scaled_calibration(
|
||||||
std::transform(
|
m_calibration, [](ControlState val) { return val * CALIBRATION_CONFIG_SCALE; });
|
||||||
m_calibration.begin(), m_calibration.end(), save_data.begin(),
|
section->Set(group + CALIBRATION_CONFIG_NAME,
|
||||||
[](ControlState val) { return fmt::format("{:.2f}", val * CALIBRATION_CONFIG_SCALE); });
|
fmt::format("{:.2f}", fmt::join(scaled_calibration, " ")), "");
|
||||||
section->Set(group + CALIBRATION_CONFIG_NAME, fmt::to_string(fmt::join(save_data, " ")), "");
|
|
||||||
|
|
||||||
// Save center value.
|
// Save center value.
|
||||||
static constexpr char center_format[] = "{:.2f} {:.2f}";
|
static constexpr char center_format[] = "{:.2f} {:.2f}";
|
||||||
|
|
|
@ -915,7 +915,7 @@ static void ResetRumbleLockNeeded()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fill(std::begin(s_controller_rumble), std::end(s_controller_rumble), 0);
|
s_controller_rumble.fill(0);
|
||||||
|
|
||||||
std::array<u8, CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
|
std::array<u8, CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
|
||||||
0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2],
|
0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2],
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
@ -18,6 +17,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
#include <fmt/ranges.h>
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
|
|
||||||
#include "Common/BitUtils.h"
|
#include "Common/BitUtils.h"
|
||||||
|
@ -642,10 +642,7 @@ std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database)
|
||||||
}
|
}
|
||||||
if (info.empty())
|
if (info.empty())
|
||||||
return name;
|
return name;
|
||||||
std::ostringstream ss;
|
return fmt::format("{} ({})", name, fmt::join(info, ", "));
|
||||||
std::copy(info.begin(), info.end() - 1, std::ostream_iterator<std::string>(ss, ", "));
|
|
||||||
ss << info.back();
|
|
||||||
return name + " (" + ss.str() + ")";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Common::SHA1::Digest GetHash(u32 value)
|
static Common::SHA1::Digest GetHash(u32 value)
|
||||||
|
|
Loading…
Reference in New Issue