From df7248039553b3ebd338380c3ef0428b0e046e79 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 14 Aug 2020 09:38:45 -0400 Subject: common: Make use of [[nodiscard]] where applicable Now that clang-format makes [[nodiscard]] attributes format sensibly, we can apply them to several functions within the common library to allow the compiler to complain about any misuses of the functions. --- src/common/lz4_compression.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/common/lz4_compression.h') diff --git a/src/common/lz4_compression.h b/src/common/lz4_compression.h index 173f9b9ad..088ff5c91 100644 --- a/src/common/lz4_compression.h +++ b/src/common/lz4_compression.h @@ -18,7 +18,7 @@ namespace Common::Compression { * * @return the compressed data. */ -std::vector CompressDataLZ4(std::span source); +[[nodiscard]] std::vector CompressDataLZ4(std::span source); /** * Utilizes the LZ4 subalgorithm LZ4HC with the specified compression level. Higher compression @@ -31,7 +31,7 @@ std::vector CompressDataLZ4(std::span source); * * @return the compressed data. */ -std::vector CompressDataLZ4HC(std::span source, s32 compression_level); +[[nodiscard]] std::vector CompressDataLZ4HC(std::span source, s32 compression_level); /** * Utilizes the LZ4 subalgorithm LZ4HC with the highest possible compression level. @@ -40,7 +40,7 @@ std::vector CompressDataLZ4HC(std::span source, s32 compression_le * * @return the compressed data. */ -std::vector CompressDataLZ4HCMax(std::span source); +[[nodiscard]] std::vector CompressDataLZ4HCMax(std::span source); /** * Decompresses a source memory region with LZ4 and returns the uncompressed data in a vector. @@ -50,6 +50,7 @@ std::vector CompressDataLZ4HCMax(std::span source); * * @return the decompressed data. */ -std::vector DecompressDataLZ4(const std::vector& compressed, std::size_t uncompressed_size); +[[nodiscard]] std::vector DecompressDataLZ4(const std::vector& compressed, + std::size_t uncompressed_size); } // namespace Common::Compression \ No newline at end of file -- cgit v1.2.3 From 1ee060ca0dfae7d0a1c830c7495f3125acf0ec7f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 15 Aug 2020 05:25:28 -0400 Subject: common/compression: Roll back std::span changes Seems like all compilers don't support std::span yet. --- src/common/lz4_compression.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/common/lz4_compression.h') diff --git a/src/common/lz4_compression.h b/src/common/lz4_compression.h index 088ff5c91..87a4be1b0 100644 --- a/src/common/lz4_compression.h +++ b/src/common/lz4_compression.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include "common/common_types.h" @@ -14,11 +13,12 @@ namespace Common::Compression { /** * Compresses a source memory region with LZ4 and returns the compressed data in a vector. * - * @param source the uncompressed source memory region. + * @param source The uncompressed source memory region. + * @param source_size The size of the uncompressed source memory region. * * @return the compressed data. */ -[[nodiscard]] std::vector CompressDataLZ4(std::span source); +[[nodiscard]] std::vector CompressDataLZ4(const u8* source, std::size_t source_size); /** * Utilizes the LZ4 subalgorithm LZ4HC with the specified compression level. Higher compression @@ -26,21 +26,24 @@ namespace Common::Compression { * compression level has almost no impact on decompression speed. Data compressed with LZ4HC can * also be decompressed with the default LZ4 decompression. * - * @param source the uncompressed source memory region. - * @param compression_level the used compression level. Should be between 3 and 12. + * @param source The uncompressed source memory region. + * @param source_size The size of the uncompressed source memory region. + * @param compression_level The used compression level. Should be between 3 and 12. * * @return the compressed data. */ -[[nodiscard]] std::vector CompressDataLZ4HC(std::span source, s32 compression_level); +[[nodiscard]] std::vector CompressDataLZ4HC(const u8* source, std::size_t source_size, + s32 compression_level); /** * Utilizes the LZ4 subalgorithm LZ4HC with the highest possible compression level. * - * @param source the uncompressed source memory region. + * @param source The uncompressed source memory region. + * @param source_size The size of the uncompressed source memory region * * @return the compressed data. */ -[[nodiscard]] std::vector CompressDataLZ4HCMax(std::span source); +[[nodiscard]] std::vector CompressDataLZ4HCMax(const u8* source, std::size_t source_size); /** * Decompresses a source memory region with LZ4 and returns the uncompressed data in a vector. -- cgit v1.2.3