From b82fb4f77c83c14dbb34a1b5189f67018bba7a65 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Tue, 29 Nov 2016 11:37:10 -0800 Subject: [PATCH] Support old LZ4 versions 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 | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/folly/io/Compression.cpp b/folly/io/Compression.cpp index c7c4c8f8..aaed2374 100644 --- a/folly/io/Compression.cpp +++ b/folly/io/Compression.cpp @@ -259,20 +259,22 @@ std::unique_ptr LZ4Codec::doCompress(const IOBuf* data) { } int n; + auto input = reinterpret_cast(data->data()); + auto output = reinterpret_cast(out->writableTail()); + const auto inputLength = data->length(); +#if LZ4_VERSION_NUMBER >= 10700 if (highCompression_) { - n = LZ4_compress_HC( - reinterpret_cast(data->data()), - reinterpret_cast(out->writableTail()), - data->length(), - out->tailroom(), - 0); + n = LZ4_compress_HC(input, output, inputLength, out->tailroom(), 0); } else { - n = LZ4_compress_default( - reinterpret_cast(data->data()), - reinterpret_cast(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()); -- 2.34.1