mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	code: Use std::span where appropriate (#6658)
* code: Use std::span when possible * code: Prefix memcpy and memcmp with std::
This commit is contained in:
		
							parent
							
								
									4ccd9f24fb
								
							
						
					
					
						commit
						cf9bb90ae3
					
				
					 106 changed files with 362 additions and 329 deletions
				
			
		|  | @ -855,7 +855,7 @@ const std::string& GetDefaultUserPath(UserPath path) { | |||
|     return g_default_paths[path]; | ||||
| } | ||||
| 
 | ||||
| const void UpdateUserPath(UserPath path, const std::string& filename) { | ||||
| void UpdateUserPath(UserPath path, const std::string& filename) { | ||||
|     if (filename.empty()) { | ||||
|         return; | ||||
|     } | ||||
|  |  | |||
|  | @ -191,7 +191,7 @@ void SetCurrentRomPath(const std::string& path); | |||
| [[nodiscard]] const std::string& GetDefaultUserPath(UserPath path); | ||||
| 
 | ||||
| // Update the Global Path with the new value
 | ||||
| const void UpdateUserPath(UserPath path, const std::string& filename); | ||||
| void UpdateUserPath(UserPath path, const std::string& filename); | ||||
| 
 | ||||
| // Returns the path to where the sys file are
 | ||||
| [[nodiscard]] std::string GetSysDirectory(); | ||||
|  |  | |||
|  | @ -154,7 +154,7 @@ private: | |||
| 
 | ||||
|     struct Header { | ||||
|         Header() : id(*(u32*)"DCAC"), key_t_size(sizeof(K)), value_t_size(sizeof(V)) { | ||||
|             memcpy(ver, scm_rev_git_str, 40); | ||||
|             std::memcpy(ver, scm_rev_git_str, 40); | ||||
|         } | ||||
| 
 | ||||
|         const u32 id; | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ | |||
| #include <cstring> | ||||
| #include <limits> | ||||
| #include <new> | ||||
| #include <span> | ||||
| #include <type_traits> | ||||
| #include <vector> | ||||
| #include "common/common_types.h" | ||||
|  | @ -57,7 +58,7 @@ public: | |||
|         return push_count; | ||||
|     } | ||||
| 
 | ||||
|     std::size_t Push(const std::vector<T>& input) { | ||||
|     std::size_t Push(std::span<const T> input) { | ||||
|         return Push(input.data(), input.size() / granularity); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -56,7 +56,7 @@ static CPUCaps Detect() { | |||
|     // Citra at all anyway
 | ||||
| 
 | ||||
|     int cpu_id[4]; | ||||
|     memset(caps.brand_string, 0, sizeof(caps.brand_string)); | ||||
|     std::memset(caps.brand_string, 0, sizeof(caps.brand_string)); | ||||
| 
 | ||||
|     // Detect CPU's CPUID capabilities and grab CPU string
 | ||||
|     __cpuid(cpu_id, 0x00000000); | ||||
|  |  | |||
|  | @ -5,19 +5,18 @@ | |||
| #include <algorithm> | ||||
| #include <zstd.h> | ||||
| 
 | ||||
| #include "common/assert.h" | ||||
| #include "common/zstd_compression.h" | ||||
| 
 | ||||
| namespace Common::Compression { | ||||
| 
 | ||||
| std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, s32 compression_level) { | ||||
| std::vector<u8> CompressDataZSTD(std::span<const u8> source, s32 compression_level) { | ||||
|     compression_level = std::clamp(compression_level, ZSTD_minCLevel(), ZSTD_maxCLevel()); | ||||
| 
 | ||||
|     const std::size_t max_compressed_size = ZSTD_compressBound(source_size); | ||||
|     const std::size_t max_compressed_size = ZSTD_compressBound(source.size()); | ||||
|     std::vector<u8> compressed(max_compressed_size); | ||||
| 
 | ||||
|     const std::size_t compressed_size = | ||||
|         ZSTD_compress(compressed.data(), compressed.size(), source, source_size, compression_level); | ||||
|     const std::size_t compressed_size = ZSTD_compress( | ||||
|         compressed.data(), compressed.size(), source.data(), source.size(), compression_level); | ||||
| 
 | ||||
|     if (ZSTD_isError(compressed_size)) { | ||||
|         // Compression failed
 | ||||
|  | @ -29,11 +28,11 @@ std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, s32 | |||
|     return compressed; | ||||
| } | ||||
| 
 | ||||
| std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_size) { | ||||
|     return CompressDataZSTD(source, source_size, ZSTD_CLEVEL_DEFAULT); | ||||
| std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source) { | ||||
|     return CompressDataZSTD(source, ZSTD_CLEVEL_DEFAULT); | ||||
| } | ||||
| 
 | ||||
| std::vector<u8> DecompressDataZSTD(const std::vector<u8>& compressed) { | ||||
| std::vector<u8> DecompressDataZSTD(std::span<const u8> compressed) { | ||||
|     const std::size_t decompressed_size = | ||||
|         ZSTD_getFrameContentSize(compressed.data(), compressed.size()); | ||||
|     std::vector<u8> decompressed(decompressed_size); | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <span> | ||||
| #include <vector> | ||||
| 
 | ||||
| #include "common/common_types.h" | ||||
|  | @ -14,24 +15,21 @@ namespace Common::Compression { | |||
|  * Compresses a source memory region with Zstandard and returns the compressed data in a vector. | ||||
|  * | ||||
|  * @param source the uncompressed source memory region. | ||||
|  * @param source_size the size in bytes of the uncompressed source memory region. | ||||
|  * @param compression_level the used compression level. Should be between 1 and 22. | ||||
|  * | ||||
|  * @return the compressed data. | ||||
|  */ | ||||
| [[nodiscard]] std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, | ||||
|                                                s32 compression_level); | ||||
| [[nodiscard]] std::vector<u8> CompressDataZSTD(std::span<const u8> source, s32 compression_level); | ||||
| 
 | ||||
| /**
 | ||||
|  * Compresses a source memory region with Zstandard with the default compression level and returns | ||||
|  * the compressed data in a vector. | ||||
|  * | ||||
|  * @param source the uncompressed source memory region. | ||||
|  * @param source_size the size in bytes of the uncompressed source memory region. | ||||
|  * | ||||
|  * @return the compressed data. | ||||
|  */ | ||||
| [[nodiscard]] std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_size); | ||||
| [[nodiscard]] std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source); | ||||
| 
 | ||||
| /**
 | ||||
|  * Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector. | ||||
|  | @ -40,6 +38,6 @@ namespace Common::Compression { | |||
|  * | ||||
|  * @return the decompressed data. | ||||
|  */ | ||||
| [[nodiscard]] std::vector<u8> DecompressDataZSTD(const std::vector<u8>& compressed); | ||||
| [[nodiscard]] std::vector<u8> DecompressDataZSTD(std::span<const u8> compressed); | ||||
| 
 | ||||
| } // namespace Common::Compression
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue