Commit 89003304 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/compression/

Summary: [Folly] Apply `clang-format` to `folly/compression/`.

Reviewed By: igorsugak

Differential Revision: D9625742

fbshipit-source-id: 5098aa62a3f5d9cc12da0932ab4f33d5a11111dc
parent b75576a1
......@@ -573,8 +573,8 @@ NoCompressionCodec::NoCompressionCodec(int level, CodecType type)
level = 0;
}
if (level != 0) {
throw std::invalid_argument(to<std::string>(
"NoCompressionCodec: invalid level ", level));
throw std::invalid_argument(
to<std::string>("NoCompressionCodec: invalid level ", level));
}
}
......@@ -583,8 +583,7 @@ uint64_t NoCompressionCodec::doMaxCompressedLength(
return uncompressedLength;
}
std::unique_ptr<IOBuf> NoCompressionCodec::doCompress(
const IOBuf* data) {
std::unique_ptr<IOBuf> NoCompressionCodec::doCompress(const IOBuf* data) {
return data->clone();
}
......@@ -626,7 +625,7 @@ inline uint64_t decodeVarintFromCursor(folly::io::Cursor& cursor) {
} // namespace
#endif // FOLLY_HAVE_LIBLZ4 || FOLLY_HAVE_LIBLZMA
#endif // FOLLY_HAVE_LIBLZ4 || FOLLY_HAVE_LIBLZMA
#if FOLLY_HAVE_LIBLZ4
......@@ -660,7 +659,9 @@ class LZ4Codec final : public Codec {
uint64_t doMaxUncompressedLength() const override;
uint64_t doMaxCompressedLength(uint64_t uncompressedLength) const override;
bool encodeSize() const { return type() == CodecType::LZ4_VARINT_SIZE; }
bool encodeSize() const {
return type() == CodecType::LZ4_VARINT_SIZE;
}
std::unique_ptr<IOBuf> doCompress(const IOBuf* data) override;
std::unique_ptr<IOBuf> doUncompress(
......@@ -713,7 +714,7 @@ bool LZ4Codec::doNeedsUncompressedLength() const {
// define LZ4_MAX_INPUT_SIZE (even though the max size is the same), so do it
// here.
#ifndef LZ4_MAX_INPUT_SIZE
# define LZ4_MAX_INPUT_SIZE 0x7E000000
#define LZ4_MAX_INPUT_SIZE 0x7E000000
#endif
uint64_t LZ4Codec::doMaxUncompressedLength() const {
......@@ -812,8 +813,8 @@ std::unique_ptr<IOBuf> LZ4Codec::doUncompress(
actualUncompressedLength);
if (n < 0 || uint64_t(n) != actualUncompressedLength) {
throw std::runtime_error(to<std::string>(
"LZ4 decompression returned invalid value ", n));
throw std::runtime_error(
to<std::string>("LZ4 decompression returned invalid value ", n));
}
out->append(actualUncompressedLength);
return out;
......@@ -1044,15 +1045,14 @@ class IOBufSnappySource final : public snappy::Source {
size_t Available() const override;
const char* Peek(size_t* len) override;
void Skip(size_t n) override;
private:
size_t available_;
io::Cursor cursor_;
};
IOBufSnappySource::IOBufSnappySource(const IOBuf* data)
: available_(data->computeChainDataLength()),
cursor_(data) {
}
: available_(data->computeChainDataLength()), cursor_(data) {}
size_t IOBufSnappySource::Available() const {
return available_;
......@@ -1097,8 +1097,8 @@ SnappyCodec::SnappyCodec(int level, CodecType type) : Codec(type) {
level = 1;
}
if (level != 1) {
throw std::invalid_argument(to<std::string>(
"SnappyCodec: invalid level: ", level));
throw std::invalid_argument(
to<std::string>("SnappyCodec: invalid level: ", level));
}
}
......@@ -1115,8 +1115,8 @@ std::unique_ptr<IOBuf> SnappyCodec::doCompress(const IOBuf* data) {
IOBufSnappySource source(data);
auto out = IOBuf::create(maxCompressedLength(source.Available()));
snappy::UncheckedByteArraySink sink(reinterpret_cast<char*>(
out->writableTail()));
snappy::UncheckedByteArraySink sink(
reinterpret_cast<char*>(out->writableTail()));
size_t n = snappy::Compress(&source, &sink);
......@@ -1144,8 +1144,8 @@ std::unique_ptr<IOBuf> SnappyCodec::doUncompress(
{
IOBufSnappySource source(data);
if (!snappy::RawUncompress(&source,
reinterpret_cast<char*>(out->writableTail()))) {
if (!snappy::RawUncompress(
&source, reinterpret_cast<char*>(out->writableTail()))) {
throw std::runtime_error("snappy::RawUncompress failed");
}
}
......@@ -1154,7 +1154,7 @@ std::unique_ptr<IOBuf> SnappyCodec::doUncompress(
return out;
}
#endif // FOLLY_HAVE_LIBSNAPPY
#endif // FOLLY_HAVE_LIBSNAPPY
#if FOLLY_HAVE_LIBLZMA
......
......@@ -130,7 +130,7 @@ enum class CodecType {
class Codec {
public:
virtual ~Codec() { }
virtual ~Codec() {}
static constexpr uint64_t UNLIMITED_UNCOMPRESSED_LENGTH = uint64_t(-1);
/**
......@@ -144,7 +144,9 @@ class Codec {
/**
* Return the codec's type.
*/
CodecType type() const { return type_; }
CodecType type() const {
return type_;
}
/**
* Does this codec need the exact uncompressed length on decompression?
......
......@@ -41,7 +41,7 @@ bool isValidStrategy(int strategy) {
Z_FILTERED,
Z_HUFFMAN_ONLY,
Z_RLE,
Z_FIXED
Z_FIXED,
}};
return std::any_of(strategies.begin(), strategies.end(), [&](int i) {
return i == strategy;
......
......@@ -61,9 +61,7 @@ class DataHolder : private boost::noncopyable {
};
DataHolder::DataHolder(size_t sizeLog2)
: size_(size_t(1) << sizeLog2),
data_(new uint8_t[size_]) {
}
: size_(size_t(1) << sizeLog2), data_(new uint8_t[size_]) {}
uint64_t DataHolder::hash(size_t size) const {
CHECK_LE(size, size_);
......@@ -95,8 +93,7 @@ class RandomDataHolder : public DataHolder {
explicit RandomDataHolder(size_t sizeLog2);
};
RandomDataHolder::RandomDataHolder(size_t sizeLog2)
: DataHolder(sizeLog2) {
RandomDataHolder::RandomDataHolder(size_t sizeLog2) : DataHolder(sizeLog2) {
static constexpr size_t numThreadsLog2 = 3;
static constexpr size_t numThreads = size_t(1) << numThreadsLog2;
......@@ -125,12 +122,11 @@ class ConstantDataHolder : public DataHolder {
explicit ConstantDataHolder(size_t sizeLog2);
};
ConstantDataHolder::ConstantDataHolder(size_t sizeLog2)
: DataHolder(sizeLog2) {
ConstantDataHolder::ConstantDataHolder(size_t sizeLog2) : DataHolder(sizeLog2) {
memset(data_.get(), 'a', size_);
}
constexpr size_t dataSizeLog2 = 27; // 128MiB
constexpr size_t dataSizeLog2 = 27; // 128MiB
RandomDataHolder randomDataHolder(dataSizeLog2);
ConstantDataHolder constantDataHolder(dataSizeLog2);
......@@ -139,10 +135,7 @@ static std::vector<CodecType> supportedCodecs(std::vector<CodecType> const& v) {
std::vector<CodecType> supported;
std::copy_if(
std::begin(v),
std::end(v),
std::back_inserter(supported),
hasCodec);
std::begin(v), std::end(v), std::back_inserter(supported), hasCodec);
return supported;
}
......@@ -194,8 +187,9 @@ TEST(CompressionTestNeedsUncompressedLength, Simple) {
for (auto const& test : expectations) {
if (hasCodec(test.type)) {
EXPECT_EQ(getCodec(test.type)->needsUncompressedLength(),
test.needsUncompressedLength);
EXPECT_EQ(
getCodec(test.type)->needsUncompressedLength(),
test.needsUncompressedLength);
}
}
}
......@@ -236,8 +230,8 @@ void CompressionTest::runSimpleIOBufTest(const DataHolder& dh) {
EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get()));
}
{
auto uncompressed = codec_->uncompress(compressed.get(),
uncompressedLength_);
auto uncompressed =
codec_->uncompress(compressed.get(), uncompressedLength_);
EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength());
EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get()));
}
......@@ -342,8 +336,8 @@ void CompressionVarintTest::runSimpleTest(const DataHolder& dh) {
1UL +
Random::rand64(
std::max(uint64_t(9), oneBasedMsbPos(uncompressedLength_)) / 9UL);
auto tinyBuf = IOBuf::copyBuffer(compressed->data(),
std::min(compressed->length(), breakPoint));
auto tinyBuf = IOBuf::copyBuffer(
compressed->data(), std::min(compressed->length(), breakPoint));
compressed->trimStart(breakPoint);
tinyBuf->prependChain(std::move(compressed));
compressed = std::move(tinyBuf);
......@@ -386,7 +380,9 @@ TEST(LZMATest, UncompressBadVarint) {
class CompressionCorruptionTest : public testing::TestWithParam<CodecType> {
protected:
void SetUp() override { codec_ = getCodec(GetParam()); }
void SetUp() override {
codec_ = getCodec(GetParam());
}
void runSimpleTest(const DataHolder& dh);
......@@ -404,26 +400,27 @@ void CompressionCorruptionTest::runSimpleTest(const DataHolder& dh) {
EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get()));
}
{
auto uncompressed = codec_->uncompress(compressed.get(),
uncompressedLength);
auto uncompressed =
codec_->uncompress(compressed.get(), uncompressedLength);
EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get()));
}
EXPECT_THROW(codec_->uncompress(compressed.get(), uncompressedLength + 1),
std::runtime_error);
EXPECT_THROW(
codec_->uncompress(compressed.get(), uncompressedLength + 1),
std::runtime_error);
auto corrupted = compressed->clone();
corrupted->unshare();
// Truncate the last character
corrupted->prev()->trimEnd(1);
if (!codec_->needsUncompressedLength()) {
EXPECT_THROW(codec_->uncompress(corrupted.get()),
std::runtime_error);
EXPECT_THROW(codec_->uncompress(corrupted.get()), std::runtime_error);
}
EXPECT_THROW(codec_->uncompress(corrupted.get(), uncompressedLength),
std::runtime_error);
EXPECT_THROW(
codec_->uncompress(corrupted.get(), uncompressedLength),
std::runtime_error);
corrupted = compressed->clone();
corrupted->unshare();
......@@ -431,12 +428,12 @@ void CompressionCorruptionTest::runSimpleTest(const DataHolder& dh) {
++(corrupted->writableData()[0]);
if (!codec_->needsUncompressedLength()) {
EXPECT_THROW(codec_->uncompress(corrupted.get()),
std::runtime_error);
EXPECT_THROW(codec_->uncompress(corrupted.get()), std::runtime_error);
}
EXPECT_THROW(codec_->uncompress(corrupted.get(), uncompressedLength),
std::runtime_error);
EXPECT_THROW(
codec_->uncompress(corrupted.get(), uncompressedLength),
std::runtime_error);
}
TEST_P(CompressionCorruptionTest, RandomData) {
......@@ -667,9 +664,8 @@ TEST_P(StreamingUnitTest, stateTransitions) {
auto outBuffer = IOBuf::create(codec_->maxCompressedLength(in.size()));
MutableByteRange const out{outBuffer->writableTail(), outBuffer->tailroom()};
auto compress = [&](
StreamCodec::FlushOp flushOp = StreamCodec::FlushOp::NONE,
bool empty = false) {
auto compress = [&](StreamCodec::FlushOp flushOp = StreamCodec::FlushOp::NONE,
bool empty = false) {
auto input = in;
auto output = empty ? MutableByteRange{} : out;
return codec_->compressStream(input, output, flushOp);
......@@ -688,9 +684,9 @@ TEST_P(StreamingUnitTest, stateTransitions) {
}
}
};
auto uncompress = [&](
StreamCodec::FlushOp flushOp = StreamCodec::FlushOp::NONE,
bool empty = false) {
auto uncompress = [&](StreamCodec::FlushOp flushOp =
StreamCodec::FlushOp::NONE,
bool empty = false) {
auto input = in;
auto output = empty ? MutableByteRange{} : out;
return codec_->uncompressStream(input, output, flushOp);
......
......@@ -44,11 +44,7 @@ TEST(FollyCountersTest, SumWorks) {
TEST(FollyCountersTest, AvgWorks) {
CompressionCounter counter(
kCodecType,
kCodecName,
folly::none,
kKey,
CompressionCounterType::AVG);
kCodecType, kCodecName, folly::none, kKey, CompressionCounterType::AVG);
for (int i = 0; i < 100; ++i) {
counter += 5;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment