Merge pull request #11516 from lioncash/spans

ActionReplay/GeckoCode: Make use of std::span where applicable
This commit is contained in:
Admiral H. Curtiss 2023-01-30 19:14:41 +01:00 committed by GitHub
commit 8960f6f07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 15 deletions

View File

@ -112,7 +112,7 @@ struct ARAddr
// ---------------------- // ----------------------
// AR Remote Functions // AR Remote Functions
void ApplyCodes(const std::vector<ARCode>& codes) void ApplyCodes(std::span<const ARCode> codes)
{ {
if (!Config::Get(Config::MAIN_ENABLE_CHEATS)) if (!Config::Get(Config::MAIN_ENABLE_CHEATS))
return; return;
@ -132,7 +132,7 @@ void SetSyncedCodesAsActive()
s_active_codes = s_synced_codes; s_active_codes = s_synced_codes;
} }
void UpdateSyncedCodes(const std::vector<ARCode>& codes) void UpdateSyncedCodes(std::span<const ARCode> codes)
{ {
s_synced_codes.clear(); s_synced_codes.clear();
s_synced_codes.reserve(codes.size()); s_synced_codes.reserve(codes.size());
@ -141,7 +141,7 @@ void UpdateSyncedCodes(const std::vector<ARCode>& codes)
s_synced_codes.shrink_to_fit(); s_synced_codes.shrink_to_fit();
} }
std::vector<ARCode> ApplyAndReturnCodes(const std::vector<ARCode>& codes) std::vector<ARCode> ApplyAndReturnCodes(std::span<const ARCode> codes)
{ {
if (Config::Get(Config::MAIN_ENABLE_CHEATS)) if (Config::Get(Config::MAIN_ENABLE_CHEATS))
{ {
@ -250,7 +250,7 @@ std::vector<ARCode> LoadCodes(const IniFile& global_ini, const IniFile& local_in
return codes; return codes;
} }
void SaveCodes(IniFile* local_ini, const std::vector<ARCode>& codes) void SaveCodes(IniFile* local_ini, std::span<const ARCode> codes)
{ {
std::vector<std::string> lines; std::vector<std::string> lines;
std::vector<std::string> enabled_lines; std::vector<std::string> enabled_lines;

View File

@ -3,8 +3,8 @@
#pragma once #pragma once
#include <span>
#include <string> #include <string>
#include <utility>
#include <variant> #include <variant>
#include <vector> #include <vector>
@ -37,15 +37,15 @@ struct ARCode
void RunAllActive(); void RunAllActive();
void ApplyCodes(const std::vector<ARCode>& codes); void ApplyCodes(std::span<const ARCode> codes);
void SetSyncedCodesAsActive(); void SetSyncedCodesAsActive();
void UpdateSyncedCodes(const std::vector<ARCode>& codes); void UpdateSyncedCodes(std::span<const ARCode> codes);
std::vector<ARCode> ApplyAndReturnCodes(const std::vector<ARCode>& codes); std::vector<ARCode> ApplyAndReturnCodes(std::span<const ARCode> codes);
void AddCode(ARCode new_code); void AddCode(ARCode new_code);
void LoadAndApplyCodes(const IniFile& global_ini, const IniFile& local_ini); void LoadAndApplyCodes(const IniFile& global_ini, const IniFile& local_ini);
std::vector<ARCode> LoadCodes(const IniFile& global_ini, const IniFile& local_ini); std::vector<ARCode> LoadCodes(const IniFile& global_ini, const IniFile& local_ini);
void SaveCodes(IniFile* local_ini, const std::vector<ARCode>& codes); void SaveCodes(IniFile* local_ini, std::span<const ARCode> codes);
using EncryptedLine = std::string; using EncryptedLine = std::string;
std::variant<std::monostate, AREntry, EncryptedLine> DeserializeLine(const std::string& line); std::variant<std::monostate, AREntry, EncryptedLine> DeserializeLine(const std::string& line);

View File

@ -66,7 +66,7 @@ static std::vector<GeckoCode> s_active_codes;
static std::vector<GeckoCode> s_synced_codes; static std::vector<GeckoCode> s_synced_codes;
static std::mutex s_active_codes_lock; static std::mutex s_active_codes_lock;
void SetActiveCodes(const std::vector<GeckoCode>& gcodes) void SetActiveCodes(std::span<const GeckoCode> gcodes)
{ {
std::lock_guard lk(s_active_codes_lock); std::lock_guard lk(s_active_codes_lock);
@ -89,7 +89,7 @@ void SetSyncedCodesAsActive()
s_active_codes = s_synced_codes; s_active_codes = s_synced_codes;
} }
void UpdateSyncedCodes(const std::vector<GeckoCode>& gcodes) void UpdateSyncedCodes(std::span<const GeckoCode> gcodes)
{ {
s_synced_codes.clear(); s_synced_codes.clear();
s_synced_codes.reserve(gcodes.size()); s_synced_codes.reserve(gcodes.size());
@ -98,7 +98,7 @@ void UpdateSyncedCodes(const std::vector<GeckoCode>& gcodes)
s_synced_codes.shrink_to_fit(); s_synced_codes.shrink_to_fit();
} }
std::vector<GeckoCode> SetAndReturnActiveCodes(const std::vector<GeckoCode>& gcodes) std::vector<GeckoCode> SetAndReturnActiveCodes(std::span<const GeckoCode> gcodes)
{ {
std::lock_guard lk(s_active_codes_lock); std::lock_guard lk(s_active_codes_lock);

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <span>
#include <string> #include <string>
#include <vector> #include <vector>
@ -58,10 +59,10 @@ constexpr u32 HLE_TRAMPOLINE_ADDRESS = INSTALLER_END_ADDRESS - 4;
// preserve the emulation performance. // preserve the emulation performance.
constexpr u32 MAGIC_GAMEID = 0xD01F1BAD; constexpr u32 MAGIC_GAMEID = 0xD01F1BAD;
void SetActiveCodes(const std::vector<GeckoCode>& gcodes); void SetActiveCodes(std::span<const GeckoCode> gcodes);
void SetSyncedCodesAsActive(); void SetSyncedCodesAsActive();
void UpdateSyncedCodes(const std::vector<GeckoCode>& gcodes); void UpdateSyncedCodes(std::span<const GeckoCode> gcodes);
std::vector<GeckoCode> SetAndReturnActiveCodes(const std::vector<GeckoCode>& gcodes); std::vector<GeckoCode> SetAndReturnActiveCodes(std::span<const GeckoCode> gcodes);
void RunCodeHandler(); void RunCodeHandler();
void Shutdown(); void Shutdown();
void DoState(PointerWrap&); void DoState(PointerWrap&);