Support old LZ4 versions
authorNick Terrell <terrelln@fb.com>
Tue, 29 Nov 2016 19:37:10 +0000 (11:37 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Tue, 29 Nov 2016 19:38:31 +0000 (11:38 -0800)
Summary: D4194834 broke the OSS build.  Ubuntu 14.4 has r114 in its repo, so support it.

Reviewed By: yfeldblum

Differential Revision: D4224129

fbshipit-source-id: c85e95716ee1a08b33455bfe6fc9f7712d226edf

folly/io/Compression.cpp

index c7c4c8f8dd05d22ce743094a9404db0b69eaddde..aaed2374b83d545497d695356a7ea5abf22d5794 100644 (file)
@@ -259,20 +259,22 @@ std::unique_ptr<IOBuf> LZ4Codec::doCompress(const IOBuf* data) {
   }
 
   int n;
+  auto input = reinterpret_cast<const char*>(data->data());
+  auto output = reinterpret_cast<char*>(out->writableTail());
+  const auto inputLength = data->length();
+#if LZ4_VERSION_NUMBER >= 10700
   if (highCompression_) {
-    n = LZ4_compress_HC(
-        reinterpret_cast<const char*>(data->data()),
-        reinterpret_cast<char*>(out->writableTail()),
-        data->length(),
-        out->tailroom(),
-        0);
+    n = LZ4_compress_HC(input, output, inputLength, out->tailroom(), 0);
   } else {
-    n = LZ4_compress_default(
-        reinterpret_cast<const char*>(data->data()),
-        reinterpret_cast<char*>(out->writableTail()),
-        data->length(),
-        out->tailroom());
+    n = LZ4_compress_default(input, output, inputLength, out->tailroom());
   }
+#else
+  if (highCompression_) {
+    n = LZ4_compressHC(input, output, inputLength);
+  } else {
+    n = LZ4_compress(input, output, inputLength);
+  }
+#endif
 
   CHECK_GE(n, 0);
   CHECK_LE(n, out->capacity());