summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common/zstd_compression.cpp13
-rw-r--r--src/common/zstd_compression.h7
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp3
3 files changed, 10 insertions, 13 deletions
diff --git a/src/common/zstd_compression.cpp b/src/common/zstd_compression.cpp
index 978526492..770833ee7 100644
--- a/src/common/zstd_compression.cpp
+++ b/src/common/zstd_compression.cpp
@@ -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, 1, 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,8 +28,8 @@ 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) {
diff --git a/src/common/zstd_compression.h b/src/common/zstd_compression.h
index e9de941c8..b5edf19e7 100644
--- a/src/common/zstd_compression.h
+++ b/src/common/zstd_compression.h
@@ -4,6 +4,7 @@
#pragma once
+#include <span>
#include <vector>
#include "common/common_types.h"
@@ -14,23 +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.
*/
-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);
/**
* 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.
*/
-std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_size);
+std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source);
/**
* Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector.
diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
index 2dcc2b0eb..c0e73789b 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
@@ -422,8 +422,7 @@ void ShaderDiskCacheOpenGL::SavePrecompiledHeaderToVirtualPrecompiledCache() {
void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() {
precompiled_cache_virtual_file_offset = 0;
const std::vector<u8> uncompressed = precompiled_cache_virtual_file.ReadAllBytes();
- const std::vector<u8> compressed =
- Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size());
+ const std::vector<u8> compressed = Common::Compression::CompressDataZSTDDefault(uncompressed);
const auto precompiled_path{GetPrecompiledPath()};
FileUtil::IOFile file(precompiled_path, "wb");