clang-tidy: readability-redundant and performance (#1298)
* clang-tidy: readability-redundant-*
* clang-tidy: performance-*
diff --git a/.clang-tidy b/.clang-tidy
index c518599..56938a5 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,6 +1,6 @@
---
-Checks: 'clang-analyzer-*'
-WarningsAsErrors: 'clang-analyzer-*'
+Checks: 'clang-analyzer-*,readability-redundant-*,performance-*'
+WarningsAsErrors: 'clang-analyzer-*,readability-redundant-*,performance-*'
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: none
diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h
index 4fdb545..c8ced38 100644
--- a/include/benchmark/benchmark.h
+++ b/include/benchmark/benchmark.h
@@ -774,7 +774,7 @@
bool finished_;
bool error_occurred_;
- private: // items we don't need on the first cache line
+ // items we don't need on the first cache line
std::vector<int64_t> range_;
int64_t complexity_n_;
@@ -1054,7 +1054,8 @@
Benchmark* Complexity(BigOFunc* complexity);
// Add this statistics to be computed over all the values of benchmark run
- Benchmark* ComputeStatistics(std::string name, StatisticsFunc* statistics,
+ Benchmark* ComputeStatistics(const std::string& name,
+ StatisticsFunc* statistics,
StatisticUnit unit = kTime);
// Support for running multiple copies of the same benchmark concurrently
@@ -1169,8 +1170,7 @@
LambdaBenchmark(LambdaBenchmark const&) = delete;
- private:
- template <class Lam>
+ template <class Lam> // NOLINTNEXTLINE(readability-redundant-declaration)
friend Benchmark* ::benchmark::RegisterBenchmark(const char*, Lam&&);
Lambda lambda_;
@@ -1338,7 +1338,7 @@
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
class BaseClass##_##Method##_Benchmark : public BaseClass { \
public: \
- BaseClass##_##Method##_Benchmark() : BaseClass() { \
+ BaseClass##_##Method##_Benchmark() { \
this->SetName(#BaseClass "/" #Method); \
} \
\
@@ -1349,7 +1349,7 @@
#define BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \
class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \
public: \
- BaseClass##_##Method##_Benchmark() : BaseClass<a>() { \
+ BaseClass##_##Method##_Benchmark() { \
this->SetName(#BaseClass "<" #a ">/" #Method); \
} \
\
@@ -1360,7 +1360,7 @@
#define BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \
class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \
public: \
- BaseClass##_##Method##_Benchmark() : BaseClass<a, b>() { \
+ BaseClass##_##Method##_Benchmark() { \
this->SetName(#BaseClass "<" #a "," #b ">/" #Method); \
} \
\
@@ -1372,7 +1372,7 @@
#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(BaseClass, Method, ...) \
class BaseClass##_##Method##_Benchmark : public BaseClass<__VA_ARGS__> { \
public: \
- BaseClass##_##Method##_Benchmark() : BaseClass<__VA_ARGS__>() { \
+ BaseClass##_##Method##_Benchmark() { \
this->SetName(#BaseClass "<" #__VA_ARGS__ ">/" #Method); \
} \
\
@@ -1539,7 +1539,6 @@
complexity_n(0),
report_big_o(false),
report_rms(false),
- counters(),
memory_result(NULL),
allocs_per_iter(0.0) {}
@@ -1676,10 +1675,7 @@
OO_Defaults = OO_ColorTabular
};
explicit ConsoleReporter(OutputOptions opts_ = OO_Defaults)
- : output_options_(opts_),
- name_field_width_(0),
- prev_counters_(),
- printed_header_(false) {}
+ : output_options_(opts_), name_field_width_(0), printed_header_(false) {}
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE;
virtual void ReportRuns(const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
diff --git a/src/benchmark.cc b/src/benchmark.cc
index f9a0a6c..cedeee3 100644
--- a/src/benchmark.cc
+++ b/src/benchmark.cc
@@ -145,7 +145,6 @@
error_occurred_(false),
range_(ranges),
complexity_n_(0),
- counters(),
thread_index_(thread_i),
threads_(n_threads),
timer_(timer),
@@ -434,7 +433,7 @@
}
size_t RunSpecifiedBenchmarks(std::string spec) {
- return RunSpecifiedBenchmarks(nullptr, nullptr, spec);
+ return RunSpecifiedBenchmarks(nullptr, nullptr, std::move(spec));
}
size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter) {
@@ -444,7 +443,7 @@
size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
std::string spec) {
- return RunSpecifiedBenchmarks(display_reporter, nullptr, spec);
+ return RunSpecifiedBenchmarks(display_reporter, nullptr, std::move(spec));
}
size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
diff --git a/src/benchmark_register.cc b/src/benchmark_register.cc
index b3f85dc..61a0c26 100644
--- a/src/benchmark_register.cc
+++ b/src/benchmark_register.cc
@@ -413,7 +413,7 @@
return this;
}
-Benchmark* Benchmark::ComputeStatistics(std::string name,
+Benchmark* Benchmark::ComputeStatistics(const std::string& name,
StatisticsFunc* statistics,
StatisticUnit unit) {
statistics_.emplace_back(name, statistics, unit);
diff --git a/src/thread_manager.h b/src/thread_manager.h
index 28e2dd5..4680285 100644
--- a/src/thread_manager.h
+++ b/src/thread_manager.h
@@ -36,7 +36,6 @@
[this]() { return alive_threads_ == 0; });
}
- public:
struct Result {
IterationCount iterations = 0;
double real_time_used = 0;
diff --git a/test/args_product_test.cc b/test/args_product_test.cc
index d081f6f..d44f391 100644
--- a/test/args_product_test.cc
+++ b/test/args_product_test.cc
@@ -37,7 +37,7 @@
virtual ~ArgsProductFixture() {
if (actualValues != expectedValues) {
std::cout << "EXPECTED\n";
- for (auto v : expectedValues) {
+ for (const auto& v : expectedValues) {
std::cout << "{";
for (int64_t iv : v) {
std::cout << iv << ", ";
@@ -45,7 +45,7 @@
std::cout << "}\n";
}
std::cout << "ACTUAL\n";
- for (auto v : actualValues) {
+ for (const auto& v : actualValues) {
std::cout << "{";
for (int64_t iv : v) {
std::cout << iv << ", ";
diff --git a/test/benchmark_random_interleaving_gtest.cc b/test/benchmark_random_interleaving_gtest.cc
index 88e274e..d04befa 100644
--- a/test/benchmark_random_interleaving_gtest.cc
+++ b/test/benchmark_random_interleaving_gtest.cc
@@ -111,8 +111,8 @@
std::vector<std::string> interleaving;
interleaving.push_back(queue->Get());
interleaving.push_back(queue->Get());
- element_count[interleaving[0].c_str()]++;
- element_count[interleaving[1].c_str()]++;
+ element_count[interleaving[0]]++;
+ element_count[interleaving[1]]++;
interleaving_count[StrFormat("%s,%s", interleaving[0].c_str(),
interleaving[1].c_str())]++;
}
diff --git a/test/complexity_test.cc b/test/complexity_test.cc
index 132d3ae..1251cd4 100644
--- a/test/complexity_test.cc
+++ b/test/complexity_test.cc
@@ -13,9 +13,10 @@
#define ADD_COMPLEXITY_CASES(...) \
int CONCAT(dummy, __LINE__) = AddComplexityTest(__VA_ARGS__)
-int AddComplexityTest(std::string test_name, std::string big_o_test_name,
- std::string rms_test_name, std::string big_o,
- int family_index) {
+int AddComplexityTest(const std::string &test_name,
+ const std::string &big_o_test_name,
+ const std::string &rms_test_name,
+ const std::string &big_o, int family_index) {
SetSubstitutions({{"%name", test_name},
{"%bigo_name", big_o_test_name},
{"%rms_name", rms_test_name},
diff --git a/test/multiple_ranges_test.cc b/test/multiple_ranges_test.cc
index 8f1b962..7618c4d 100644
--- a/test/multiple_ranges_test.cc
+++ b/test/multiple_ranges_test.cc
@@ -42,7 +42,7 @@
virtual ~MultipleRangesFixture() {
if (actualValues != expectedValues) {
std::cout << "EXPECTED\n";
- for (auto v : expectedValues) {
+ for (const auto& v : expectedValues) {
std::cout << "{";
for (int64_t iv : v) {
std::cout << iv << ", ";
@@ -50,7 +50,7 @@
std::cout << "}\n";
}
std::cout << "ACTUAL\n";
- for (auto v : actualValues) {
+ for (const auto& v : actualValues) {
std::cout << "{";
for (int64_t iv : v) {
std::cout << iv << ", ";
diff --git a/test/output_test.h b/test/output_test.h
index 82ae752..c6ff8ef 100644
--- a/test/output_test.h
+++ b/test/output_test.h
@@ -85,7 +85,7 @@
struct Results;
typedef std::function<void(Results const&)> ResultsCheckFn;
-size_t AddChecker(const char* bm_name_pattern, ResultsCheckFn fn);
+size_t AddChecker(const char* bm_name_pattern, const ResultsCheckFn& fn);
// Class holding the results of a benchmark.
// It is passed in calls to checker functions.
diff --git a/test/output_test_helper.cc b/test/output_test_helper.cc
index b7f06f5..81584cb 100644
--- a/test/output_test_helper.cc
+++ b/test/output_test_helper.cc
@@ -141,7 +141,7 @@
class TestReporter : public benchmark::BenchmarkReporter {
public:
TestReporter(std::vector<benchmark::BenchmarkReporter*> reps)
- : reporters_(reps) {}
+ : reporters_(std::move(reps)) {}
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE {
bool last_ret = false;
@@ -183,7 +183,7 @@
public:
struct PatternAndFn : public TestCase { // reusing TestCase for its regexes
PatternAndFn(const std::string& rx, ResultsCheckFn fn_)
- : TestCase(rx), fn(fn_) {}
+ : TestCase(rx), fn(std::move(fn_)) {}
ResultsCheckFn fn;
};
@@ -191,7 +191,7 @@
std::vector<Results> results;
std::vector<std::string> field_names;
- void Add(const std::string& entry_pattern, ResultsCheckFn fn);
+ void Add(const std::string& entry_pattern, const ResultsCheckFn& fn);
void CheckResults(std::stringstream& output);
@@ -210,7 +210,8 @@
}
// add a results checker for a benchmark
-void ResultsChecker::Add(const std::string& entry_pattern, ResultsCheckFn fn) {
+void ResultsChecker::Add(const std::string& entry_pattern,
+ const ResultsCheckFn& fn) {
check_patterns.emplace_back(entry_pattern, fn);
}
@@ -299,7 +300,7 @@
} // end namespace internal
-size_t AddChecker(const char* bm_name, ResultsCheckFn fn) {
+size_t AddChecker(const char* bm_name, const ResultsCheckFn& fn) {
auto& rc = internal::GetResultsChecker();
rc.Add(bm_name, fn);
return rc.results.size();
diff --git a/test/register_benchmark_test.cc b/test/register_benchmark_test.cc
index 74c6e7e..602405b 100644
--- a/test/register_benchmark_test.cc
+++ b/test/register_benchmark_test.cc
@@ -45,7 +45,7 @@
std::vector<TestCase> ExpectedResults;
int AddCases(std::initializer_list<TestCase> const& v) {
- for (auto N : v) {
+ for (const auto& N : v) {
ExpectedResults.push_back(N);
}
return 0;
diff --git a/test/skip_with_error_test.cc b/test/skip_with_error_test.cc
index 5e9700d..026d479 100644
--- a/test/skip_with_error_test.cc
+++ b/test/skip_with_error_test.cc
@@ -119,12 +119,13 @@
void BM_error_during_running_ranged_for(benchmark::State& state) {
assert(state.max_iterations > 3 && "test requires at least a few iterations");
- [[maybe_unused]] bool first_iter = true;
+ bool first_iter = true;
// NOTE: Users should not write the for loop explicitly.
for (auto It = state.begin(), End = state.end(); It != End; ++It) {
if (state.range(0) == 1) {
assert(first_iter);
first_iter = false;
+ (void)first_iter;
state.SkipWithError("error message");
// Test the unfortunate but documented behavior that the ranged-for loop
// doesn't automatically terminate when SkipWithError is set.