From c9212708b251a5b49ade2389d6a9315f1dd8e736 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Sun, 3 Nov 2019 23:22:24 -0800 Subject: [PATCH] Fix build errors. PiperOrigin-RevId: 278310119 --- snappy-test.cc | 13 +++++++------ snappy-test.h | 2 +- snappy_unittest.cc | 15 ++++++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/snappy-test.cc b/snappy-test.cc index 20524b2..83be2d3 100644 --- a/snappy-test.cc +++ b/snappy-test.cc @@ -67,7 +67,7 @@ std::string ReadTestDataFile(const std::string& base) { return ReadTestDataFile(base, 0); } -std::string StringPrintf(const char* format, ...) { +std::string StrFormat(const char* format, ...) { char buf[4096]; va_list ap; va_start(ap, format); @@ -217,7 +217,7 @@ void Benchmark::Run() { benchmark_runs[run].cpu_time_us = benchmark_cpu_time_us; } - std::string heading = StringPrintf("%s/%d", name_.c_str(), test_case_num); + std::string heading = StrFormat("%s/%d", name_.c_str(), test_case_num); std::string human_readable_speed; std::nth_element(benchmark_runs, @@ -232,15 +232,16 @@ void Benchmark::Run() { int64 bytes_per_second = benchmark_bytes_processed * 1000000 / cpu_time_us; if (bytes_per_second < 1024) { - human_readable_speed = StringPrintf("%dB/s", bytes_per_second); + human_readable_speed = + StrFormat("%dB/s", static_cast(bytes_per_second)); } else if (bytes_per_second < 1024 * 1024) { - human_readable_speed = StringPrintf( + human_readable_speed = StrFormat( "%.1fkB/s", bytes_per_second / 1024.0f); } else if (bytes_per_second < 1024 * 1024 * 1024) { - human_readable_speed = StringPrintf( + human_readable_speed = StrFormat( "%.1fMB/s", bytes_per_second / (1024.0f * 1024.0f)); } else { - human_readable_speed = StringPrintf( + human_readable_speed = StrFormat( "%.1fGB/s", bytes_per_second / (1024.0f * 1024.0f * 1024.0f)); } } diff --git a/snappy-test.h b/snappy-test.h index 1996896..c8b7d38 100644 --- a/snappy-test.h +++ b/snappy-test.h @@ -187,7 +187,7 @@ std::string ReadTestDataFile(const std::string& base); // A sprintf() variant that returns a std::string. // Not safe for general use due to truncation issues. -std::string StringPrintf(const char* format, ...); +std::string StrFormat(const char* format, ...); // A wall-time clock. This stub is not super-accurate, nor resistant to the // system time changing. diff --git a/snappy_unittest.cc b/snappy_unittest.cc index d627f7f..82291c4 100644 --- a/snappy_unittest.cc +++ b/snappy_unittest.cc @@ -346,7 +346,7 @@ static void Measure(const char* data, float uncomp_rate = (length / utime[med]) * repeats / 1048576.0; std::string x = names[comp]; x += ":"; - std::string urate = (uncomp_rate >= 0) ? absl::StrFormat("%.1f", uncomp_rate) + std::string urate = (uncomp_rate >= 0) ? StrFormat("%.1f", uncomp_rate) : std::string("?"); printf("%-7s [b %dM] bytes %6d -> %6d %4.1f%% " "comp %5.1f MB/s uncomp %5s MB/s\n", @@ -582,7 +582,7 @@ TEST(CorruptedTest, VerifyCorrupted) { // try reading stuff in from a bad file. for (int i = 1; i <= 3; ++i) { std::string data = - ReadTestDataFile(absl::StrFormat("baddata%d.snappy", i).c_str(), 0); + ReadTestDataFile(StrFormat("baddata%d.snappy", i).c_str(), 0); std::string uncmp; // check that we don't return a crazy length size_t ulen; @@ -1401,10 +1401,11 @@ static void BM_ZFlat(int iters, int arg) { StopBenchmarkTiming(); const double compression_ratio = static_cast(zsize) / std::max(1, contents.size()); - SetBenchmarkLabel(absl::StrFormat("%s (%.2f %%)", files[arg].label, - 100.0 * compression_ratio)); - VLOG(0) << StringPrintf("compression for %s: %zd -> %zd bytes", - files[arg].label, contents.size(), zsize); + SetBenchmarkLabel(StrFormat("%s (%.2f %%)", files[arg].label, + 100.0 * compression_ratio)); + VLOG(0) << StrFormat("compression for %s: %zd -> %zd bytes", + files[arg].label, static_cast(contents.size()), + static_cast(zsize)); delete[] dst; } BENCHMARK(BM_ZFlat)->DenseRange(0, ARRAYSIZE(files) - 1); @@ -1440,7 +1441,7 @@ static void BM_ZFlatAll(int iters, int arg) { for (int i = 0; i < num_files; ++i) { delete[] dst[i]; } - SetBenchmarkLabel(absl::StrFormat("%d files", num_files)); + SetBenchmarkLabel(StrFormat("%d files", num_files)); } BENCHMARK(BM_ZFlatAll)->DenseRange(0, 0);