From 1044bc40ca87c5a3bfcb1be038e47861f2bca0d8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 12:49:35 -0400 Subject: [PATCH 1/2] GCMemcardUtils: Make use of std::span where applicable Generifies bits of the interface so that some functions aren't explicitly tied down to only using std::vector. --- Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp | 6 +++--- Source/Core/Core/HW/GCMemcard/GCMemcardUtils.h | 9 ++++++--- Source/Core/DolphinQt/GCMemcardManager.cpp | 2 +- Source/Core/DolphinQt/GCMemcardManager.h | 5 ++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp index c7cc7942f8..e16b452774 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp @@ -75,7 +75,7 @@ bool HasSameIdentity(const DEntry& lhs, const DEntry& rhs) return true; } -bool HasDuplicateIdentity(const std::vector& savefiles) +bool HasDuplicateIdentity(std::span savefiles) { for (size_t i = 0; i < savefiles.size(); ++i) { @@ -338,7 +338,7 @@ std::string GetDefaultExtension(SavefileFormat format) } } -std::vector GetSavefiles(const GCMemcard& card, const std::vector& file_indices) +std::vector GetSavefiles(const GCMemcard& card, std::span file_indices) { std::vector files; files.reserve(file_indices.size()); @@ -352,7 +352,7 @@ std::vector GetSavefiles(const GCMemcard& card, const std::vector& return files; } -size_t GetBlockCount(const std::vector& savefiles) +size_t GetBlockCount(std::span savefiles) { size_t block_count = 0; for (const Savefile& savefile : savefiles) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.h b/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.h index 4aa74fdce9..b4d0624888 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.h @@ -3,8 +3,11 @@ #pragma once +#include +#include #include #include +#include #include "Core/HW/GCMemcard/GCMemcard.h" @@ -13,7 +16,7 @@ namespace Memcard bool HasSameIdentity(const DEntry& lhs, const DEntry& rhs); // Check if any two given savefiles have the same identity. -bool HasDuplicateIdentity(const std::vector& savefiles); +bool HasDuplicateIdentity(std::span savefiles); enum class ReadSavefileErrorCode { @@ -43,8 +46,8 @@ std::string GenerateFilename(const DEntry& entry); std::string GetDefaultExtension(SavefileFormat format); // Reads multiple savefiles from a card. Returns empty vector if even a single file can't be read. -std::vector GetSavefiles(const GCMemcard& card, const std::vector& file_indices); +std::vector GetSavefiles(const GCMemcard& card, std::span file_indices); // Gets the total amount of blocks the given saves use. -size_t GetBlockCount(const std::vector& savefiles); +size_t GetBlockCount(std::span savefiles); } // namespace Memcard diff --git a/Source/Core/DolphinQt/GCMemcardManager.cpp b/Source/Core/DolphinQt/GCMemcardManager.cpp index 8f7646774a..8bbe9061dc 100644 --- a/Source/Core/DolphinQt/GCMemcardManager.cpp +++ b/Source/Core/DolphinQt/GCMemcardManager.cpp @@ -502,7 +502,7 @@ void GCMemcardManager::ExportFiles(Memcard::SavefileFormat format) } } -void GCMemcardManager::ImportFiles(Slot slot, const std::vector& savefiles) +void GCMemcardManager::ImportFiles(Slot slot, std::span savefiles) { auto& card = m_slot_memcard[slot]; if (!card) diff --git a/Source/Core/DolphinQt/GCMemcardManager.h b/Source/Core/DolphinQt/GCMemcardManager.h index 838a7750d7..dcc4b3324b 100644 --- a/Source/Core/DolphinQt/GCMemcardManager.h +++ b/Source/Core/DolphinQt/GCMemcardManager.h @@ -3,10 +3,9 @@ #pragma once -#include #include #include -#include +#include #include #include @@ -62,7 +61,7 @@ private: std::vector GetSelectedFileIndices(); - void ImportFiles(ExpansionInterface::Slot slot, const std::vector& savefiles); + void ImportFiles(ExpansionInterface::Slot slot, std::span savefiles); void CopyFiles(); void ImportFile(); From 349add0f81a37f9a51f970ef2cb1cef7ca35946c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 13:05:10 -0400 Subject: [PATCH 2/2] GCMemcardManager: Shorten-up EnumMap definitions We can make a small alias that gets rid of the need to repeat the long constant. --- Source/Core/DolphinQt/GCMemcardManager.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/Core/DolphinQt/GCMemcardManager.h b/Source/Core/DolphinQt/GCMemcardManager.h index dcc4b3324b..f87d001d8a 100644 --- a/Source/Core/DolphinQt/GCMemcardManager.h +++ b/Source/Core/DolphinQt/GCMemcardManager.h @@ -88,16 +88,17 @@ private: QPushButton* m_fix_checksums_button; // Slots - Common::EnumMap, ExpansionInterface::MAX_MEMCARD_SLOT> - m_slot_active_icons; - Common::EnumMap, ExpansionInterface::MAX_MEMCARD_SLOT> - m_slot_memcard; - Common::EnumMap m_slot_group; - Common::EnumMap m_slot_file_edit; - Common::EnumMap m_slot_open_button; - Common::EnumMap m_slot_create_button; - Common::EnumMap m_slot_table; - Common::EnumMap m_slot_stat_label; + template + using SlotEnumMap = Common::EnumMap; + + SlotEnumMap> m_slot_active_icons; + SlotEnumMap> m_slot_memcard; + SlotEnumMap m_slot_group; + SlotEnumMap m_slot_file_edit; + SlotEnumMap m_slot_open_button; + SlotEnumMap m_slot_create_button; + SlotEnumMap m_slot_table; + SlotEnumMap m_slot_stat_label; ExpansionInterface::Slot m_active_slot; u64 m_current_frame = 0;