diff options
| author | tobo <[email protected]> | 2025-07-01 07:59:20 +0300 |
|---|---|---|
| committer | tobo <[email protected]> | 2025-07-01 08:11:16 +0300 |
| commit | 4691e7646dfd4daeb3659c192a3afe0d92050d79 (patch) | |
| tree | c575f210f10daf4590eb4c6d2273e4f09e9f5d64 /library/cpp/blockcodecs/codecs/zstd/zstd.cpp | |
| parent | cb27087e9c7261d7ec0b415e44dbdc3e316ef035 (diff) | |
add zstd fast levels from 1 to 7
zstd supports negative compression levels (`--fast=XXX` param in zstd CLI), so add them here also
commit_hash:ed7231a6f341cd120dfea0d4b0b481962df835ab
Diffstat (limited to 'library/cpp/blockcodecs/codecs/zstd/zstd.cpp')
| -rw-r--r-- | library/cpp/blockcodecs/codecs/zstd/zstd.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/library/cpp/blockcodecs/codecs/zstd/zstd.cpp b/library/cpp/blockcodecs/codecs/zstd/zstd.cpp index 95299b3f6d3..3846ab85802 100644 --- a/library/cpp/blockcodecs/codecs/zstd/zstd.cpp +++ b/library/cpp/blockcodecs/codecs/zstd/zstd.cpp @@ -5,36 +5,38 @@ #define ZSTD_STATIC_LINKING_ONLY #include <contrib/libs/zstd/include/zstd.h> +#include <utility> + using namespace NBlockCodecs; namespace { struct TZStd08Codec: public TAddLengthCodec<TZStd08Codec> { - inline TZStd08Codec(unsigned level) + TZStd08Codec(int level, TString name) : Level(level) - , MyName(TStringBuf("zstd08_") + ToString(Level)) + , MyName(std::move(name)) { } - static inline size_t CheckError(size_t ret, const char* what) { - if (ZSTD_isError(ret)) { + static size_t CheckError(size_t ret, const char* what) { + if (Y_UNLIKELY(ZSTD_isError(ret))) { ythrow yexception() << what << TStringBuf(" zstd error: ") << ZSTD_getErrorName(ret); } return ret; } - static inline size_t DoMaxCompressedLength(size_t l) noexcept { + static size_t DoMaxCompressedLength(size_t l) noexcept { return ZSTD_compressBound(l); } - inline size_t DoCompress(const TData& in, void* out) const { + size_t DoCompress(const TData& in, void* out) const { return CheckError(ZSTD_compress(out, DoMaxCompressedLength(in.size()), in.data(), in.size(), Level), "compress"); } - inline void DoDecompress(const TData& in, void* out, size_t dsize) const { + static void DoDecompress(const TData& in, void* out, size_t dsize) { const size_t res = CheckError(ZSTD_decompress(out, dsize, in.data(), in.size()), "decompress"); - if (res != dsize) { + if (Y_UNLIKELY(res != dsize)) { ythrow TDecompressError(dsize, res); } } @@ -43,15 +45,20 @@ namespace { return MyName; } - const unsigned Level; + const int Level; const TString MyName; }; struct TZStd08Registrar { TZStd08Registrar() { for (int i = 1; i <= ZSTD_maxCLevel(); ++i) { - RegisterCodec(MakeHolder<TZStd08Codec>(i)); - RegisterAlias("zstd_" + ToString(i), "zstd08_" + ToString(i)); + const TString name = "zstd08_"sv + ToString(i); + RegisterCodec(MakeHolder<TZStd08Codec>(i, name)); + RegisterAlias("zstd_"sv + ToString(i), name); + } + + for (int i = 1; i <= 7; ++i) { + RegisterCodec(MakeHolder<TZStd08Codec>(-i, "zstd_fast_"sv + ToString(i))); } } }; |
