From 6b2eb7028bfec6685a9643ab802f5eaadd52719a Mon Sep 17 00:00:00 2001 From: Danila Kutenin Date: Thu, 4 Apr 2024 19:00:14 +0000 Subject: [PATCH] Fix all compilation errors to be C++11 compliant --- snappy.h | 3 +++ snappy_benchmark.cc | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/snappy.h b/snappy.h index 04b7a96..bde378b 100644 --- a/snappy.h +++ b/snappy.h @@ -64,6 +64,9 @@ namespace snappy { // faster decompression speeds than snappy:1 and zstd:-3. int level = DefaultCompressionLevel(); + constexpr CompressionOptions() = default; + constexpr CompressionOptions(int compression_level) + : level(compression_level) {} static constexpr int MinCompressionLevel() { return 1; } static constexpr int MaxCompressionLevel() { return 2; } static constexpr int DefaultCompressionLevel() { return 1; } diff --git a/snappy_benchmark.cc b/snappy_benchmark.cc index 60110d4..d6e35d3 100644 --- a/snappy_benchmark.cc +++ b/snappy_benchmark.cc @@ -31,12 +31,10 @@ #include #include -#include "snappy-test.h" - #include "benchmark/benchmark.h" - #include "snappy-internal.h" #include "snappy-sinksource.h" +#include "snappy-test.h" #include "snappy.h" #include "snappy_test_data.h" @@ -44,7 +42,7 @@ namespace snappy { namespace { -void FilesAndLevels(::testing::Benchmark* benchmark) { +void FilesAndLevels(benchmark::internal::Benchmark* benchmark) { for (int i = 0; i < ARRAYSIZE(kTestDataFiles); ++i) { for (int level = snappy::CompressionOptions::MinCompressionLevel(); level <= snappy::CompressionOptions::MaxCompressionLevel(); ++level) { @@ -64,8 +62,9 @@ void BM_UFlat(benchmark::State& state) { kTestDataFiles[file_index].size_limit); std::string zcontents; - snappy::Compress(contents.data(), contents.size(), &zcontents, - snappy::CompressionOptions{/*level=*/state.range(1)}); + snappy::Compress( + contents.data(), contents.size(), &zcontents, + snappy::CompressionOptions{/*level=*/static_cast(state.range(1))}); char* dst = new char[contents.size()]; for (auto s : state) { @@ -129,8 +128,9 @@ void BM_UValidate(benchmark::State& state) { kTestDataFiles[file_index].size_limit); std::string zcontents; - snappy::Compress(contents.data(), contents.size(), &zcontents, - snappy::CompressionOptions{/*level=*/state.range(1)}); + snappy::Compress( + contents.data(), contents.size(), &zcontents, + snappy::CompressionOptions{/*level=*/static_cast(state.range(1))}); for (auto s : state) { CHECK(snappy::IsValidCompressedBuffer(zcontents.data(), zcontents.size())); @@ -226,7 +226,7 @@ void BM_UIOVecSink(benchmark::State& state) { // Uncompress into an iovec containing ten entries. const int kNumEntries = 10; struct iovec iov[kNumEntries]; - char *dst = new char[contents.size()]; + char* dst = new char[contents.size()]; size_t used_so_far = 0; for (int i = 0; i < kNumEntries; ++i) { iov[i].iov_base = dst + used_so_far; @@ -267,8 +267,9 @@ void BM_UFlatSink(benchmark::State& state) { kTestDataFiles[file_index].size_limit); std::string zcontents; - snappy::Compress(contents.data(), contents.size(), &zcontents, - snappy::CompressionOptions{/*level=*/state.range(1)}); + snappy::Compress( + contents.data(), contents.size(), &zcontents, + snappy::CompressionOptions{/*level=*/static_cast(state.range(1))}); char* dst = new char[contents.size()]; for (auto s : state) { @@ -323,7 +324,7 @@ BENCHMARK(BM_ZFlat)->Apply(FilesAndLevels); void BM_ZFlatAll(benchmark::State& state) { const int num_files = ARRAYSIZE(kTestDataFiles); - int/*level=*/state.range(0); + int level = state.range(0); std::vector contents(num_files); std::vector dst(num_files);