diff options
author | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
commit | cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a (patch) | |
tree | f647b20e1823f1846af88e832cf82a4a02e96e69 /src/StringCompression.cpp | |
parent | Improve clang-format config file, remove automatically enforced code style from contrib guide. (diff) | |
download | cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.gz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.bz2 cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.lz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.xz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.zst cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.zip |
Diffstat (limited to 'src/StringCompression.cpp')
-rw-r--r-- | src/StringCompression.cpp | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/StringCompression.cpp b/src/StringCompression.cpp index 6678fe1bd..5a0feca9f 100644 --- a/src/StringCompression.cpp +++ b/src/StringCompression.cpp @@ -16,7 +16,7 @@ std::string_view Compression::Result::GetStringView() const { const auto View = GetView(); - return { reinterpret_cast<const char *>(View.data()), View.size() }; + return {reinterpret_cast<const char *>(View.data()), View.size()}; } @@ -26,21 +26,24 @@ std::string_view Compression::Result::GetStringView() const ContiguousByteBufferView Compression::Result::GetView() const { // Get a generic std::byte * to what the variant is currently storing: - return - { - std::visit([](const auto & Buffer) -> const std::byte * - { - using Variant = std::decay_t<decltype(Buffer)>; - - if constexpr (std::is_same_v<Variant, Compression::Result::Static>) - { - return Buffer.data(); - } - else + return { + std::visit( + [](const auto & Buffer) -> const std::byte * { - return Buffer.get(); - } - }, Storage), Size + using Variant = std::decay_t<decltype(Buffer)>; + + if constexpr (std::is_same_v<Variant, Compression::Result::Static>) + { + return Buffer.data(); + } + else + { + return Buffer.get(); + } + }, + Storage + ), + Size }; } @@ -81,7 +84,7 @@ Compression::Result Compression::Compressor::Compress(const void * const Input, if (BytesWrittenOut != 0) { - return { Buffer, BytesWrittenOut }; + return {Buffer, BytesWrittenOut}; } } @@ -96,7 +99,7 @@ Compression::Result Compression::Compressor::Compress(const void * const Input, if (BytesWrittenOut != 0) { - return { std::move(Dynamic), BytesWrittenOut }; + return {std::move(Dynamic), BytesWrittenOut}; } DynamicCapacity *= 2; @@ -184,8 +187,7 @@ Compression::Result Compression::Extractor::ExtractZLib(ContiguousByteBufferView -template <auto Algorithm> -Compression::Result Compression::Extractor::Extract(const ContiguousByteBufferView Input) +template <auto Algorithm> Compression::Result Compression::Extractor::Extract(const ContiguousByteBufferView Input) { // First see if the stack buffer has enough space: { @@ -194,9 +196,9 @@ Compression::Result Compression::Extractor::Extract(const ContiguousByteBufferVi switch (Algorithm(m_Handle, Input.data(), Input.size(), Buffer.data(), Buffer.size(), &BytesWrittenOut)) { - case LIBDEFLATE_SUCCESS: return { Buffer, BytesWrittenOut }; + case LIBDEFLATE_SUCCESS: return {Buffer, BytesWrittenOut}; case LIBDEFLATE_INSUFFICIENT_SPACE: break; - default: throw std::runtime_error("Data extraction failed."); + default: throw std::runtime_error("Data extraction failed."); } } @@ -210,7 +212,7 @@ Compression::Result Compression::Extractor::Extract(const ContiguousByteBufferVi switch (Algorithm(m_Handle, Input.data(), Input.size(), Dynamic.get(), DynamicCapacity, &BytesWrittenOut)) { - case libdeflate_result::LIBDEFLATE_SUCCESS: return { std::move(Dynamic), BytesWrittenOut }; + case libdeflate_result::LIBDEFLATE_SUCCESS: return {std::move(Dynamic), BytesWrittenOut}; case libdeflate_result::LIBDEFLATE_INSUFFICIENT_SPACE: { DynamicCapacity *= 2; @@ -231,20 +233,18 @@ Compression::Result Compression::Extractor::Extract(const ContiguousByteBufferVi // Here we have the expected size after extraction, so directly use a suitable buffer size: if (UncompressedSize <= Result::StaticCapacity) { - if ( - Result::Static Buffer; - Algorithm(m_Handle, Input.data(), Input.size(), Buffer.data(), UncompressedSize, nullptr) == libdeflate_result::LIBDEFLATE_SUCCESS - ) + if (Result::Static Buffer; + Algorithm(m_Handle, Input.data(), Input.size(), Buffer.data(), UncompressedSize, nullptr) == + libdeflate_result::LIBDEFLATE_SUCCESS) { - return { Buffer, UncompressedSize }; + return {Buffer, UncompressedSize}; } } - else if ( - auto Dynamic = cpp20::make_unique_for_overwrite<Result::Dynamic::element_type[]>(UncompressedSize); - Algorithm(m_Handle, Input.data(), Input.size(), Dynamic.get(), UncompressedSize, nullptr) == libdeflate_result::LIBDEFLATE_SUCCESS - ) + else if (auto Dynamic = cpp20::make_unique_for_overwrite<Result::Dynamic::element_type[]>(UncompressedSize); + Algorithm(m_Handle, Input.data(), Input.size(), Dynamic.get(), UncompressedSize, nullptr) == + libdeflate_result::LIBDEFLATE_SUCCESS) { - return { std::move(Dynamic), UncompressedSize }; + return {std::move(Dynamic), UncompressedSize}; } throw std::runtime_error("Data extraction failed."); |