From 61497236ddc0d797a47ef612831fb6ab34dc5c9d Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Wed, 7 Mar 2018 03:20:06 -0800 Subject: [PATCH] Make string_util naming more consistent (#547) * Rename StringXxx to StrXxx in string_util.h and its users This makes the naming consistent within string_util and moves is the Abseil convention. * Style guide is 2 spaces before end of line "//" comments * Rename StrPrintF/StringPrintF to StrFormat for absl compatibility. --- include/benchmark/benchmark.h | 2 +- src/benchmark_register.cc | 12 ++++++------ src/json_reporter.cc | 6 +++--- src/string_util.cc | 6 +++--- src/string_util.h | 10 +++++----- src/sysinfo.cc | 2 +- src/timers.cc | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 002331c4..9fb1f556 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -543,7 +543,7 @@ class State { // static void BM_Compress(benchmark::State& state) { // ... // double compress = input_size / output_size; - // state.SetLabel(StringPrintf("compress:%.1f%%", 100.0*compression)); + // state.SetLabel(StrFormat("compress:%.1f%%", 100.0*compression)); // } // Produces output that looks like: // BM_Compress 50 50 14115038 compress:27.3% diff --git a/src/benchmark_register.cc b/src/benchmark_register.cc index b6db262c..59b3e4da 100644 --- a/src/benchmark_register.cc +++ b/src/benchmark_register.cc @@ -172,20 +172,20 @@ bool BenchmarkFamilies::FindBenchmarks( const auto& arg_name = family->arg_names_[arg_i]; if (!arg_name.empty()) { instance.name += - StringPrintF("%s:", family->arg_names_[arg_i].c_str()); + StrFormat("%s:", family->arg_names_[arg_i].c_str()); } } - instance.name += StringPrintF("%d", arg); + instance.name += StrFormat("%d", arg); ++arg_i; } if (!IsZero(family->min_time_)) - instance.name += StringPrintF("/min_time:%0.3f", family->min_time_); + instance.name += StrFormat("/min_time:%0.3f", family->min_time_); if (family->iterations_ != 0) - instance.name += StringPrintF("/iterations:%d", family->iterations_); + instance.name += StrFormat("/iterations:%d", family->iterations_); if (family->repetitions_ != 0) - instance.name += StringPrintF("/repeats:%d", family->repetitions_); + instance.name += StrFormat("/repeats:%d", family->repetitions_); if (family->use_manual_time_) { instance.name += "/manual_time"; @@ -195,7 +195,7 @@ bool BenchmarkFamilies::FindBenchmarks( // Add the number of threads used to the name if (!family->thread_counts_.empty()) { - instance.name += StringPrintF("/threads:%d", instance.threads); + instance.name += StrFormat("/threads:%d", instance.threads); } if (re.Match(instance.name)) { diff --git a/src/json_reporter.cc b/src/json_reporter.cc index 254ec3ee..685d6b09 100644 --- a/src/json_reporter.cc +++ b/src/json_reporter.cc @@ -32,15 +32,15 @@ namespace benchmark { namespace { std::string FormatKV(std::string const& key, std::string const& value) { - return StringPrintF("\"%s\": \"%s\"", key.c_str(), value.c_str()); + return StrFormat("\"%s\": \"%s\"", key.c_str(), value.c_str()); } std::string FormatKV(std::string const& key, const char* value) { - return StringPrintF("\"%s\": \"%s\"", key.c_str(), value); + return StrFormat("\"%s\": \"%s\"", key.c_str(), value); } std::string FormatKV(std::string const& key, bool value) { - return StringPrintF("\"%s\": %s", key.c_str(), value ? "true" : "false"); + return StrFormat("\"%s\": %s", key.c_str(), value ? "true" : "false"); } std::string FormatKV(std::string const& key, int64_t value) { diff --git a/src/string_util.cc b/src/string_util.cc index 29edb2a4..ebc3aceb 100644 --- a/src/string_util.cc +++ b/src/string_util.cc @@ -122,7 +122,7 @@ std::string HumanReadableNumber(double n, double one_k) { return ToBinaryStringFullySpecified(n, 1.1, 1, one_k); } -std::string StringPrintFImp(const char* msg, va_list args) { +std::string StrFormatImp(const char* msg, va_list args) { // we might need a second shot at this, so pre-emptivly make a copy va_list args_cp; va_copy(args_cp, args); @@ -152,10 +152,10 @@ std::string StringPrintFImp(const char* msg, va_list args) { return std::string(buff_ptr.get()); } -std::string StringPrintF(const char* format, ...) { +std::string StrFormat(const char* format, ...) { va_list args; va_start(args, format); - std::string tmp = StringPrintFImp(format, args); + std::string tmp = StrFormatImp(format, args); va_end(args); return tmp; } diff --git a/src/string_util.h b/src/string_util.h index c3d53bfd..e70e7698 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -12,23 +12,23 @@ void AppendHumanReadable(int n, std::string* str); std::string HumanReadableNumber(double n, double one_k = 1024.0); -std::string StringPrintF(const char* format, ...); +std::string StrFormat(const char* format, ...); -inline std::ostream& StringCatImp(std::ostream& out) BENCHMARK_NOEXCEPT { +inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT { return out; } template -inline std::ostream& StringCatImp(std::ostream& out, First&& f, +inline std::ostream& StrCatImp(std::ostream& out, First&& f, Rest&&... rest) { out << std::forward(f); - return StringCatImp(out, std::forward(rest)...); + return StrCatImp(out, std::forward(rest)...); } template inline std::string StrCat(Args&&... args) { std::ostringstream ss; - StringCatImp(ss, std::forward(args)...); + StrCatImp(ss, std::forward(args)...); return ss.str(); } diff --git a/src/sysinfo.cc b/src/sysinfo.cc index 59769e24..dab020b5 100644 --- a/src/sysinfo.cc +++ b/src/sysinfo.cc @@ -16,7 +16,7 @@ #ifdef BENCHMARK_OS_WINDOWS #include -#undef StrCat // Don't let StrCat in string_util.h be renamed to lstrcatA +#undef StrCat // Don't let StrCat in string_util.h be renamed to lstrcatA #include #include #else diff --git a/src/timers.cc b/src/timers.cc index 701e4577..f98b9842 100644 --- a/src/timers.cc +++ b/src/timers.cc @@ -17,7 +17,7 @@ #ifdef BENCHMARK_OS_WINDOWS #include -#undef StrCat // Don't let StrCat in string_util.h be renamed to lstrcatA +#undef StrCat // Don't let StrCat in string_util.h be renamed to lstrcatA #include #include #else