Update zstd to 0.4.2
authorChip Turner <chip@fb.com>
Tue, 8 Dec 2015 15:52:02 +0000 (07:52 -0800)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Tue, 8 Dec 2015 16:20:21 +0000 (08:20 -0800)
Summary: New version.

Reviewed By: cyan

Differential Revision: D2730844

fb-gh-sync-id: 4305bdfba2e8d25eba295bbf3f13a140c0d04a1c

folly/io/Compression.cpp

index 53d36c5fd878c7597373dd6c9762470235300e0e..11fb8e3cb3738fd356ecf37ee5e2e5ae04d2a9b3 100644 (file)
@@ -939,6 +939,8 @@ class ZSTDCodec final : public Codec {
   std::unique_ptr<IOBuf> doUncompress(
       const IOBuf* data,
       uint64_t uncompressedLength) override;
+
+  int level_{1};
 };
 
 std::unique_ptr<Codec> ZSTDCodec::create(int level, CodecType type) {
@@ -947,6 +949,17 @@ std::unique_ptr<Codec> ZSTDCodec::create(int level, CodecType type) {
 
 ZSTDCodec::ZSTDCodec(int level, CodecType type) : Codec(type) {
   DCHECK(type == CodecType::ZSTD_BETA);
+  switch (level) {
+    case COMPRESSION_LEVEL_FASTEST:
+      level_ = 1;
+      break;
+    case COMPRESSION_LEVEL_DEFAULT:
+      level_ = 1;
+      break;
+    case COMPRESSION_LEVEL_BEST:
+      level_ = 19;
+      break;
+  }
 }
 
 bool ZSTDCodec::doNeedsUncompressedLength() const {
@@ -960,8 +973,11 @@ std::unique_ptr<IOBuf> ZSTDCodec::doCompress(const IOBuf* data) {
 
   CHECK_EQ(out->length(), 0);
 
-  rc = ZSTD_compress(
-      out->writableTail(), out->capacity(), data->data(), data->length());
+  rc = ZSTD_compress(out->writableTail(),
+                     out->capacity(),
+                     data->data(),
+                     data->length(),
+                     level_);
 
   if (ZSTD_isError(rc)) {
     throw std::runtime_error(to<std::string>(