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::optional<V> _val;
|
||||
|
||||
TrieEntry() { std::fill(_conns.begin(), _conns.end(), INVALID_CONN); }
|
||||
TrieEntry() { _conns.fill(INVALID_CONN); }
|
||||
};
|
||||
|
||||
constexpr size_t IndexOf(char c) const
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -575,7 +576,7 @@ SharedContentMap::GetFilenameFromSHA1(const std::array<u8, 20>& sha1) const
|
|||
if (it == m_entries.end())
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -591,20 +592,22 @@ std::vector<std::array<u8, 20>> SharedContentMap::GetHashes() const
|
|||
|
||||
std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
||||
{
|
||||
auto filename = GetFilenameFromSHA1(sha1);
|
||||
if (filename)
|
||||
return *filename;
|
||||
if (auto filename = GetFilenameFromSHA1(sha1))
|
||||
return *std::move(filename);
|
||||
|
||||
const std::string id = fmt::format("{:08x}", m_last_id);
|
||||
Entry entry;
|
||||
std::copy(id.cbegin(), id.cend(), entry.id.begin());
|
||||
Entry& entry = m_entries.emplace_back();
|
||||
static_assert(sizeof(m_last_id) == 4,
|
||||
"'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;
|
||||
m_entries.push_back(entry);
|
||||
|
||||
WriteEntries();
|
||||
filename = fmt::format("/shared1/{}.app", 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)
|
||||
|
|
|
@ -140,20 +140,14 @@ void ARCodeWidget::SortAlphabetically()
|
|||
|
||||
void ARCodeWidget::SortEnabledCodesFirst()
|
||||
{
|
||||
std::stable_sort(m_ar_codes.begin(), m_ar_codes.end(), [](const auto& a, const auto& b) {
|
||||
return a.enabled && a.enabled != b.enabled;
|
||||
});
|
||||
|
||||
std::ranges::stable_partition(m_ar_codes, std::identity{}, &ActionReplay::ARCode::enabled);
|
||||
UpdateList();
|
||||
SaveCodes();
|
||||
}
|
||||
|
||||
void ARCodeWidget::SortDisabledCodesFirst()
|
||||
{
|
||||
std::stable_sort(m_ar_codes.begin(), m_ar_codes.end(), [](const auto& a, const auto& b) {
|
||||
return !a.enabled && a.enabled != b.enabled;
|
||||
});
|
||||
|
||||
std::ranges::stable_partition(m_ar_codes, std::logical_not{}, &ActionReplay::ARCode::enabled);
|
||||
UpdateList();
|
||||
SaveCodes();
|
||||
}
|
||||
|
|
|
@ -314,20 +314,14 @@ void GeckoCodeWidget::SortAlphabetically()
|
|||
|
||||
void GeckoCodeWidget::SortEnabledCodesFirst()
|
||||
{
|
||||
std::stable_sort(m_gecko_codes.begin(), m_gecko_codes.end(), [](const auto& a, const auto& b) {
|
||||
return a.enabled && a.enabled != b.enabled;
|
||||
});
|
||||
|
||||
std::ranges::stable_partition(m_gecko_codes, std::identity{}, &Gecko::GeckoCode::enabled);
|
||||
UpdateList();
|
||||
SaveCodes();
|
||||
}
|
||||
|
||||
void GeckoCodeWidget::SortDisabledCodesFirst()
|
||||
{
|
||||
std::stable_sort(m_gecko_codes.begin(), m_gecko_codes.end(), [](const auto& a, const auto& b) {
|
||||
return !a.enabled && a.enabled != b.enabled;
|
||||
});
|
||||
|
||||
std::ranges::stable_partition(m_gecko_codes, std::logical_not{}, &Gecko::GeckoCode::enabled);
|
||||
UpdateList();
|
||||
SaveCodes();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <ranges>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ranges.h>
|
||||
|
@ -284,11 +285,10 @@ void ReshapableInput::SaveConfig(Common::IniFile::Section* section,
|
|||
50.0);
|
||||
}
|
||||
|
||||
std::vector<std::string> save_data(m_calibration.size());
|
||||
std::transform(
|
||||
m_calibration.begin(), m_calibration.end(), save_data.begin(),
|
||||
[](ControlState val) { return fmt::format("{:.2f}", val * CALIBRATION_CONFIG_SCALE); });
|
||||
section->Set(group + CALIBRATION_CONFIG_NAME, fmt::to_string(fmt::join(save_data, " ")), "");
|
||||
const std::ranges::transform_view scaled_calibration(
|
||||
m_calibration, [](ControlState val) { return val * CALIBRATION_CONFIG_SCALE; });
|
||||
section->Set(group + CALIBRATION_CONFIG_NAME,
|
||||
fmt::format("{:.2f}", fmt::join(scaled_calibration, " ")), "");
|
||||
|
||||
// Save center value.
|
||||
static constexpr char center_format[] = "{:.2f} {:.2f}";
|
||||
|
|
|
@ -915,7 +915,7 @@ static void ResetRumbleLockNeeded()
|
|||
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 = {
|
||||
0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2],
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <iterator>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
|
@ -18,6 +17,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <pugixml.hpp>
|
||||
|
||||
#include "Common/BitUtils.h"
|
||||
|
@ -642,10 +642,7 @@ std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database)
|
|||
}
|
||||
if (info.empty())
|
||||
return name;
|
||||
std::ostringstream ss;
|
||||
std::copy(info.begin(), info.end() - 1, std::ostream_iterator<std::string>(ss, ", "));
|
||||
ss << info.back();
|
||||
return name + " (" + ss.str() + ")";
|
||||
return fmt::format("{} ({})", name, fmt::join(info, ", "));
|
||||
}
|
||||
|
||||
static Common::SHA1::Digest GetHash(u32 value)
|
||||
|
|
Loading…
Reference in New Issue