From adb4c0492dd13f4a920f80d56e8afd011437bcb9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 30 Jan 2023 12:49:45 -0500 Subject: [PATCH 1/2] Core/GeckoCode: Make use of std::span where applicable Generifies the interface a little by not strictly requiring the use of std::vector. --- Source/Core/Core/GeckoCode.cpp | 6 +++--- Source/Core/Core/GeckoCode.h | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 45b176cbd2..be5ce914db 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -66,7 +66,7 @@ static std::vector s_active_codes; static std::vector s_synced_codes; static std::mutex s_active_codes_lock; -void SetActiveCodes(const std::vector& gcodes) +void SetActiveCodes(std::span gcodes) { std::lock_guard lk(s_active_codes_lock); @@ -89,7 +89,7 @@ void SetSyncedCodesAsActive() s_active_codes = s_synced_codes; } -void UpdateSyncedCodes(const std::vector& gcodes) +void UpdateSyncedCodes(std::span gcodes) { s_synced_codes.clear(); s_synced_codes.reserve(gcodes.size()); @@ -98,7 +98,7 @@ void UpdateSyncedCodes(const std::vector& gcodes) s_synced_codes.shrink_to_fit(); } -std::vector SetAndReturnActiveCodes(const std::vector& gcodes) +std::vector SetAndReturnActiveCodes(std::span gcodes) { std::lock_guard lk(s_active_codes_lock); diff --git a/Source/Core/Core/GeckoCode.h b/Source/Core/Core/GeckoCode.h index 6f2f8dff4a..fffb83303c 100644 --- a/Source/Core/Core/GeckoCode.h +++ b/Source/Core/Core/GeckoCode.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include @@ -58,10 +59,10 @@ constexpr u32 HLE_TRAMPOLINE_ADDRESS = INSTALLER_END_ADDRESS - 4; // preserve the emulation performance. constexpr u32 MAGIC_GAMEID = 0xD01F1BAD; -void SetActiveCodes(const std::vector& gcodes); +void SetActiveCodes(std::span gcodes); void SetSyncedCodesAsActive(); -void UpdateSyncedCodes(const std::vector& gcodes); -std::vector SetAndReturnActiveCodes(const std::vector& gcodes); +void UpdateSyncedCodes(std::span gcodes); +std::vector SetAndReturnActiveCodes(std::span gcodes); void RunCodeHandler(); void Shutdown(); void DoState(PointerWrap&); From f20790370a7d3bee8264ee336ed308f8990a3421 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 30 Jan 2023 12:57:40 -0500 Subject: [PATCH 2/2] Core/ActionReplay: Make use of std::span where applicable Generifies the interface a little by not strictly requiring the use of std::vector. --- Source/Core/Core/ActionReplay.cpp | 8 ++++---- Source/Core/Core/ActionReplay.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/ActionReplay.cpp b/Source/Core/Core/ActionReplay.cpp index 31e0c6766e..c702748003 100644 --- a/Source/Core/Core/ActionReplay.cpp +++ b/Source/Core/Core/ActionReplay.cpp @@ -112,7 +112,7 @@ struct ARAddr // ---------------------- // AR Remote Functions -void ApplyCodes(const std::vector& codes) +void ApplyCodes(std::span codes) { if (!Config::Get(Config::MAIN_ENABLE_CHEATS)) return; @@ -132,7 +132,7 @@ void SetSyncedCodesAsActive() s_active_codes = s_synced_codes; } -void UpdateSyncedCodes(const std::vector& codes) +void UpdateSyncedCodes(std::span codes) { s_synced_codes.clear(); s_synced_codes.reserve(codes.size()); @@ -141,7 +141,7 @@ void UpdateSyncedCodes(const std::vector& codes) s_synced_codes.shrink_to_fit(); } -std::vector ApplyAndReturnCodes(const std::vector& codes) +std::vector ApplyAndReturnCodes(std::span codes) { if (Config::Get(Config::MAIN_ENABLE_CHEATS)) { @@ -250,7 +250,7 @@ std::vector LoadCodes(const IniFile& global_ini, const IniFile& local_in return codes; } -void SaveCodes(IniFile* local_ini, const std::vector& codes) +void SaveCodes(IniFile* local_ini, std::span codes) { std::vector lines; std::vector enabled_lines; diff --git a/Source/Core/Core/ActionReplay.h b/Source/Core/Core/ActionReplay.h index 13b6294d30..1c7fb61fa9 100644 --- a/Source/Core/Core/ActionReplay.h +++ b/Source/Core/Core/ActionReplay.h @@ -3,8 +3,8 @@ #pragma once +#include #include -#include #include #include @@ -37,15 +37,15 @@ struct ARCode void RunAllActive(); -void ApplyCodes(const std::vector& codes); +void ApplyCodes(std::span codes); void SetSyncedCodesAsActive(); -void UpdateSyncedCodes(const std::vector& codes); -std::vector ApplyAndReturnCodes(const std::vector& codes); +void UpdateSyncedCodes(std::span codes); +std::vector ApplyAndReturnCodes(std::span codes); void AddCode(ARCode new_code); void LoadAndApplyCodes(const IniFile& global_ini, const IniFile& local_ini); std::vector LoadCodes(const IniFile& global_ini, const IniFile& local_ini); -void SaveCodes(IniFile* local_ini, const std::vector& codes); +void SaveCodes(IniFile* local_ini, std::span codes); using EncryptedLine = std::string; std::variant DeserializeLine(const std::string& line);