From: Nick Terrell Date: Tue, 29 Nov 2016 19:37:10 +0000 (-0800) Subject: Support old LZ4 versions X-Git-Tag: v2016.12.05.00~15 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b82fb4f77c83c14dbb34a1b5189f67018bba7a65;p=folly.git 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 --- 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());