From 00213377b1b09fadce55cc3e3562adb5c4d1e1c4 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Mon, 24 May 2021 05:28:45 -0400
Subject: [PATCH 1/2] lz4_compression: Make use of std::span

Allows making the incoming data stream non-allocating.
---
 src/common/lz4_compression.cpp | 3 +--
 src/common/lz4_compression.h   | 5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/common/lz4_compression.cpp b/src/common/lz4_compression.cpp
index 25700015ab..dbb40da7c0 100644
--- a/src/common/lz4_compression.cpp
+++ b/src/common/lz4_compression.cpp
@@ -59,8 +59,7 @@ std::vector<u8> CompressDataLZ4HCMax(const u8* source, std::size_t source_size)
     return CompressDataLZ4HC(source, source_size, LZ4HC_CLEVEL_MAX);
 }
 
-std::vector<u8> DecompressDataLZ4(const std::vector<u8>& compressed,
-                                  std::size_t uncompressed_size) {
+std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed, std::size_t uncompressed_size) {
     std::vector<u8> uncompressed(uncompressed_size);
     const int size_check = LZ4_decompress_safe(reinterpret_cast<const char*>(compressed.data()),
                                                reinterpret_cast<char*>(uncompressed.data()),
diff --git a/src/common/lz4_compression.h b/src/common/lz4_compression.h
index 87a4be1b0e..1b47175959 100644
--- a/src/common/lz4_compression.h
+++ b/src/common/lz4_compression.h
@@ -4,6 +4,7 @@
 
 #pragma once
 
+#include <span>
 #include <vector>
 
 #include "common/common_types.h"
@@ -53,7 +54,7 @@ namespace Common::Compression {
  *
  * @return the decompressed data.
  */
-[[nodiscard]] std::vector<u8> DecompressDataLZ4(const std::vector<u8>& compressed,
+[[nodiscard]] std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed,
                                                 std::size_t uncompressed_size);
 
-} // namespace Common::Compression
\ No newline at end of file
+} // namespace Common::Compression

From 49bfd0c46145b8f69e52077b83278038d514caf4 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Mon, 24 May 2021 05:32:32 -0400
Subject: [PATCH 2/2] zstd_compression: Make use of std::span

Allows for the incoming data stream to be non-allocating.
---
 src/common/zstd_compression.cpp | 2 +-
 src/common/zstd_compression.h   | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/common/zstd_compression.cpp b/src/common/zstd_compression.cpp
index 5f45459da0..695b96a430 100644
--- a/src/common/zstd_compression.cpp
+++ b/src/common/zstd_compression.cpp
@@ -32,7 +32,7 @@ std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_siz
     return CompressDataZSTD(source, source_size, 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_getDecompressedSize(compressed.data(), compressed.size());
     std::vector<u8> decompressed(decompressed_size);
diff --git a/src/common/zstd_compression.h b/src/common/zstd_compression.h
index c26a30ab9d..bbce14f4e1 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"
@@ -40,6 +41,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
\ No newline at end of file
+} // namespace Common::Compression