Skip to content

Commit adbda82

Browse files
authored
[clang-tidy] autofix readability issues (google#1931)
* [clang-tidy] autofix readability issues * more modern clang format
1 parent 2d4c8dd commit adbda82

37 files changed

Lines changed: 253 additions & 225 deletions

.github/workflows/clang-format-lint.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ jobs:
1010

1111
steps:
1212
- uses: actions/checkout@v4
13-
- uses: DoozyX/clang-format-lint-action@v0.15
13+
- uses: DoozyX/clang-format-lint-action@v0.18.2
1414
with:
1515
source: './include/benchmark ./src ./test'
16-
extensions: 'h,cc'
17-
clangFormatVersion: 12
18-
style: Google
16+
clangFormatVersion: 18

include/benchmark/benchmark.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ BENCHMARK_EXPORT std::string GetBenchmarkVersion();
313313
BENCHMARK_EXPORT void PrintDefaultHelp();
314314

315315
BENCHMARK_EXPORT void Initialize(int* argc, char** argv,
316-
void (*HelperPrinterf)() = PrintDefaultHelp);
316+
void (*HelperPrintf)() = PrintDefaultHelp);
317317
BENCHMARK_EXPORT void Shutdown();
318318

319319
// Report to stdout all arguments in 'argv' as unrecognized except the first.
@@ -631,7 +631,7 @@ class Counter {
631631
Counter(double v = 0., Flags f = kDefaults, OneK k = kIs1000)
632632
: value(v), flags(f), oneK(k) {}
633633

634-
BENCHMARK_ALWAYS_INLINE operator double const &() const { return value; }
634+
BENCHMARK_ALWAYS_INLINE operator double const&() const { return value; }
635635
BENCHMARK_ALWAYS_INLINE operator double&() { return value; }
636636
};
637637

@@ -1165,7 +1165,7 @@ class BENCHMARK_EXPORT Benchmark {
11651165
// Pass this benchmark object to *func, which can customize
11661166
// the benchmark by calling various methods like Arg, Args,
11671167
// Threads, etc.
1168-
Benchmark* Apply(void (*func)(Benchmark* benchmark));
1168+
Benchmark* Apply(void (*custom_arguments)(Benchmark* benchmark));
11691169

11701170
// Set the range multiplier for non-dense range. If not called, the range
11711171
// multiplier kRangeMultiplier will be used.
@@ -1869,8 +1869,8 @@ class BENCHMARK_EXPORT ConsoleReporter : public BenchmarkReporter {
18691869
void ReportRuns(const std::vector<Run>& reports) override;
18701870

18711871
protected:
1872-
virtual void PrintRunData(const Run& report);
1873-
virtual void PrintHeader(const Run& report);
1872+
virtual void PrintRunData(const Run& result);
1873+
virtual void PrintHeader(const Run& run);
18741874

18751875
OutputOptions output_options_;
18761876
size_t name_field_width_;
@@ -1886,7 +1886,7 @@ class BENCHMARK_EXPORT JSONReporter : public BenchmarkReporter {
18861886
void Finalize() override;
18871887

18881888
private:
1889-
void PrintRunData(const Run& report);
1889+
void PrintRunData(const Run& run);
18901890

18911891
bool first_report_;
18921892
};
@@ -1900,7 +1900,7 @@ class BENCHMARK_EXPORT BENCHMARK_DEPRECATED_MSG(
19001900
void ReportRuns(const std::vector<Run>& reports) override;
19011901

19021902
private:
1903-
void PrintRunData(const Run& report);
1903+
void PrintRunData(const Run& run);
19041904

19051905
bool printed_header_;
19061906
std::set<std::string> user_counter_names_;

src/benchmark.cc

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include "commandlineflags.h"
4747
#include "complexity.h"
4848
#include "counter.h"
49-
#include "internal_macros.h"
5049
#include "log.h"
5150
#include "mutex.h"
5251
#include "perf_counters.h"
@@ -198,7 +197,7 @@ State::State(std::string name, IterationCount max_iters,
198197
// `PauseTiming`, a new `Counter` will be inserted the first time, which
199198
// won't have the flag. Inserting them now also reduces the allocations
200199
// during the benchmark.
201-
if (perf_counters_measurement_) {
200+
if (perf_counters_measurement_ != nullptr) {
202201
for (const std::string& counter_name :
203202
perf_counters_measurement_->names()) {
204203
counters[counter_name] = Counter(0.0, Counter::kAvgIterations);
@@ -247,7 +246,7 @@ void State::PauseTiming() {
247246
// Add in time accumulated so far
248247
BM_CHECK(started_ && !finished_ && !skipped());
249248
timer_->StopTimer();
250-
if (perf_counters_measurement_) {
249+
if (perf_counters_measurement_ != nullptr) {
251250
std::vector<std::pair<std::string, double>> measurements;
252251
if (!perf_counters_measurement_->Stop(measurements)) {
253252
BM_CHECK(false) << "Perf counters read the value failed.";
@@ -265,7 +264,7 @@ void State::PauseTiming() {
265264
void State::ResumeTiming() {
266265
BM_CHECK(started_ && !finished_ && !skipped());
267266
timer_->StartTimer();
268-
if (perf_counters_measurement_) {
267+
if (perf_counters_measurement_ != nullptr) {
269268
perf_counters_measurement_->Start();
270269
}
271270
}
@@ -342,7 +341,7 @@ namespace {
342341
// Flushes streams after invoking reporter methods that write to them. This
343342
// ensures users get timely updates even when streams are not line-buffered.
344343
void FlushStreams(BenchmarkReporter* reporter) {
345-
if (!reporter) {
344+
if (reporter == nullptr) {
346345
return;
347346
}
348347
std::flush(reporter->GetOutputStream());
@@ -367,7 +366,7 @@ void Report(BenchmarkReporter* display_reporter,
367366

368367
report_one(display_reporter, run_results.display_report_aggregates_only,
369368
run_results);
370-
if (file_reporter) {
369+
if (file_reporter != nullptr) {
371370
report_one(file_reporter, run_results.file_report_aggregates_only,
372371
run_results);
373372
}
@@ -408,7 +407,7 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
408407
per_family_reports;
409408

410409
if (display_reporter->ReportContext(context) &&
411-
(!file_reporter || file_reporter->ReportContext(context))) {
410+
((file_reporter == nullptr) || file_reporter->ReportContext(context))) {
412411
FlushStreams(display_reporter);
413412
FlushStreams(file_reporter);
414413

@@ -433,12 +432,12 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
433432
if (benchmark.complexity() != oNone) {
434433
reports_for_family = &per_family_reports[benchmark.family_index()];
435434
}
436-
benchmarks_with_threads += (benchmark.threads() > 1);
435+
benchmarks_with_threads += static_cast<int>(benchmark.threads() > 1);
437436
runners.emplace_back(benchmark, &perfcounters, reports_for_family);
438437
int num_repeats_of_this_instance = runners.back().GetNumRepeats();
439438
num_repetitions_total +=
440439
static_cast<size_t>(num_repeats_of_this_instance);
441-
if (reports_for_family) {
440+
if (reports_for_family != nullptr) {
442441
reports_for_family->num_runs_total += num_repeats_of_this_instance;
443442
}
444443
}
@@ -482,7 +481,7 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
482481

483482
display_reporter->ReportRunsConfig(
484483
runner.GetMinTime(), runner.HasExplicitIters(), runner.GetIters());
485-
if (file_reporter) {
484+
if (file_reporter != nullptr) {
486485
file_reporter->ReportRunsConfig(
487486
runner.GetMinTime(), runner.HasExplicitIters(), runner.GetIters());
488487
}
@@ -506,7 +505,7 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
506505
}
507506
}
508507
display_reporter->Finalize();
509-
if (file_reporter) {
508+
if (file_reporter != nullptr) {
510509
file_reporter->Finalize();
511510
}
512511
FlushStreams(display_reporter);
@@ -569,7 +568,7 @@ ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color) {
569568
} // end namespace internal
570569

571570
BenchmarkReporter* CreateDefaultDisplayReporter() {
572-
static auto default_display_reporter =
571+
static auto* default_display_reporter =
573572
internal::CreateReporter(FLAGS_benchmark_format,
574573
internal::GetOutputOptions())
575574
.release();
@@ -611,15 +610,15 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
611610
std::ofstream output_file;
612611
std::unique_ptr<BenchmarkReporter> default_display_reporter;
613612
std::unique_ptr<BenchmarkReporter> default_file_reporter;
614-
if (!display_reporter) {
613+
if (display_reporter == nullptr) {
615614
default_display_reporter.reset(CreateDefaultDisplayReporter());
616615
display_reporter = default_display_reporter.get();
617616
}
618617
auto& Out = display_reporter->GetOutputStream();
619618
auto& Err = display_reporter->GetErrorStream();
620619

621620
std::string const& fname = FLAGS_benchmark_out;
622-
if (fname.empty() && file_reporter) {
621+
if (fname.empty() && (file_reporter != nullptr)) {
623622
Err << "A custom file reporter was provided but "
624623
"--benchmark_out=<file> was not specified.\n";
625624
Out.flush();
@@ -634,7 +633,7 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
634633
Err.flush();
635634
std::exit(1);
636635
}
637-
if (!file_reporter) {
636+
if (file_reporter == nullptr) {
638637
default_file_reporter = internal::CreateReporter(
639638
FLAGS_benchmark_out_format, FLAGS_benchmark_counters_tabular
640639
? ConsoleReporter::OO_Tabular
@@ -743,8 +742,8 @@ void SetDefaultTimeUnitFromFlag(const std::string& time_unit_flag) {
743742
void ParseCommandLineFlags(int* argc, char** argv) {
744743
using namespace benchmark;
745744
BenchmarkReporter::Context::executable_name =
746-
(argc && *argc > 0) ? argv[0] : "unknown";
747-
for (int i = 1; argc && i < *argc; ++i) {
745+
((argc != nullptr) && *argc > 0) ? argv[0] : "unknown";
746+
for (int i = 1; (argc != nullptr) && i < *argc; ++i) {
748747
if (ParseBoolFlag(argv[i], "benchmark_list_tests",
749748
&FLAGS_benchmark_list_tests) ||
750749
ParseStringFlag(argv[i], "benchmark_filter", &FLAGS_benchmark_filter) ||

src/benchmark_api_internal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ State BenchmarkInstance::Run(
101101
}
102102

103103
void BenchmarkInstance::Setup() const {
104-
if (setup_) {
104+
if (setup_ != nullptr) {
105105
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
106106
nullptr, nullptr, nullptr, nullptr);
107107
setup_(st);
108108
}
109109
}
110110

111111
void BenchmarkInstance::Teardown() const {
112-
if (teardown_) {
112+
if (teardown_ != nullptr) {
113113
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
114114
nullptr, nullptr, nullptr, nullptr);
115115
teardown_(st);

src/benchmark_api_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ namespace internal {
1717
// Information kept per benchmark we may want to run
1818
class BenchmarkInstance {
1919
public:
20-
BenchmarkInstance(Benchmark* benchmark, int family_index,
21-
int per_family_instance_index,
22-
const std::vector<int64_t>& args, int threads);
20+
BenchmarkInstance(Benchmark* benchmark, int family_idx,
21+
int per_family_instance_idx,
22+
const std::vector<int64_t>& args, int thread_count);
2323

2424
const BenchmarkName& name() const { return name_; }
2525
int family_index() const { return family_index_; }

src/benchmark_main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414

1515
#include "benchmark/benchmark.h"
1616

17-
BENCHMARK_EXPORT int main(int, char**);
17+
BENCHMARK_EXPORT int main(int /*argc*/, char** /*argv*/);
1818
BENCHMARK_MAIN();

src/benchmark_name.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ size_t size_impl(const Head& head, const Tail&... tail) {
2727
}
2828

2929
// Join a pack of std::strings using a delimiter
30-
// TODO: use absl::StrJoin
31-
void join_impl(std::string&, char) {}
30+
// TODO(dominic): use absl::StrJoin
31+
void join_impl(std::string& /*unused*/, char /*unused*/) {}
3232

3333
template <typename Head, typename... Tail>
3434
void join_impl(std::string& s, const char delimiter, const Head& head,

src/benchmark_register.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ namespace benchmark {
5353

5454
namespace {
5555
// For non-dense Range, intermediate values are powers of kRangeMultiplier.
56-
static constexpr int kRangeMultiplier = 8;
56+
constexpr int kRangeMultiplier = 8;
5757

5858
// The size of a benchmark family determines is the number of inputs to repeat
5959
// the benchmark on. If this is "large" then warn the user during configuration.
60-
static constexpr size_t kMaxFamilySize = 100;
60+
constexpr size_t kMaxFamilySize = 100;
6161

62-
static constexpr char kDisabledPrefix[] = "DISABLED_";
62+
constexpr char kDisabledPrefix[] = "DISABLED_";
6363
} // end namespace
6464

6565
namespace internal {
@@ -82,7 +82,7 @@ class BenchmarkFamilies {
8282

8383
// Extract the list of benchmark instances that match the specified
8484
// regular expression.
85-
bool FindBenchmarks(std::string re,
85+
bool FindBenchmarks(std::string spec,
8686
std::vector<BenchmarkInstance>* benchmarks,
8787
std::ostream* Err);
8888

src/benchmark_runner.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include "commandlineflags.h"
4747
#include "complexity.h"
4848
#include "counter.h"
49-
#include "internal_macros.h"
5049
#include "log.h"
5150
#include "mutex.h"
5251
#include "perf_counters.h"
@@ -74,7 +73,7 @@ ProfilerManager* profiler_manager = nullptr;
7473

7574
namespace {
7675

77-
static constexpr IterationCount kMaxIterations = 1000000000000;
76+
constexpr IterationCount kMaxIterations = 1000000000000;
7877
const double kDefaultMinTime =
7978
std::strtod(::benchmark::kDefaultMinTimeStr, /*p_end*/ nullptr);
8079

@@ -100,7 +99,7 @@ BenchmarkReporter::Run CreateRunReport(
10099
report.repetition_index = repetition_index;
101100
report.repetitions = repeats;
102101

103-
if (!report.skipped) {
102+
if (report.skipped == 0u) {
104103
if (b.use_manual_time()) {
105104
report.real_accumulated_time = results.manual_time_used;
106105
} else {
@@ -118,9 +117,10 @@ BenchmarkReporter::Run CreateRunReport(
118117
assert(memory_result != nullptr);
119118
report.memory_result = memory_result;
120119
report.allocs_per_iter =
121-
memory_iterations ? static_cast<double>(memory_result->num_allocs) /
122-
static_cast<double>(memory_iterations)
123-
: 0;
120+
memory_iterations != 0
121+
? static_cast<double>(memory_result->num_allocs) /
122+
static_cast<double>(memory_iterations)
123+
: 0;
124124
}
125125

126126
internal::Finish(&report.counters, results.iterations, seconds,
@@ -273,10 +273,11 @@ BenchmarkRunner::BenchmarkRunner(
273273
FLAGS_benchmark_report_aggregates_only;
274274
if (b.aggregation_report_mode() != internal::ARM_Unspecified) {
275275
run_results.display_report_aggregates_only =
276-
(b.aggregation_report_mode() &
277-
internal::ARM_DisplayReportAggregatesOnly);
276+
((b.aggregation_report_mode() &
277+
internal::ARM_DisplayReportAggregatesOnly) != 0u);
278278
run_results.file_report_aggregates_only =
279-
(b.aggregation_report_mode() & internal::ARM_FileReportAggregatesOnly);
279+
((b.aggregation_report_mode() &
280+
internal::ARM_FileReportAggregatesOnly) != 0u);
280281
BM_CHECK(FLAGS_benchmark_perf_counters.empty() ||
281282
(perf_counters_measurement_ptr->num_counters() == 0))
282283
<< "Perf counters were requested but could not be set up.";
@@ -364,7 +365,7 @@ bool BenchmarkRunner::ShouldReportIterationResults(
364365
// Determine if this run should be reported;
365366
// Either it has run for a sufficient amount of time
366367
// or because an error was reported.
367-
return i.results.skipped_ || FLAGS_benchmark_dry_run ||
368+
return (i.results.skipped_ != 0u) || FLAGS_benchmark_dry_run ||
368369
i.iters >= kMaxIterations || // Too many iterations already.
369370
i.seconds >=
370371
GetMinTimeToApply() || // The elapsed time is large enough.
@@ -528,9 +529,9 @@ void BenchmarkRunner::DoOneRepetition() {
528529
CreateRunReport(b, i.results, memory_iterations, memory_result, i.seconds,
529530
num_repetitions_done, repeats);
530531

531-
if (reports_for_family) {
532+
if (reports_for_family != nullptr) {
532533
++reports_for_family->num_runs_done;
533-
if (!report.skipped) {
534+
if (report.skipped == 0u) {
534535
reports_for_family->Runs.push_back(report);
535536
}
536537
}

src/benchmark_runner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value);
5151
class BenchmarkRunner {
5252
public:
5353
BenchmarkRunner(const benchmark::internal::BenchmarkInstance& b_,
54-
benchmark::internal::PerfCountersMeasurement* pmc_,
54+
benchmark::internal::PerfCountersMeasurement* pcm_,
5555
BenchmarkReporter::PerFamilyRunReports* reports_for_family);
5656

5757
int GetNumRepeats() const { return repeats; }

0 commit comments

Comments
 (0)