mirror of https://github.com/google/benchmark.git
Fix Clang-Tidy warnings readability-else-after-return (#1528)
This commit is contained in:
parent
a3235d7b69
commit
cfbc94960f
|
@ -410,14 +410,15 @@ std::unique_ptr<BenchmarkReporter> CreateReporter(
|
|||
typedef std::unique_ptr<BenchmarkReporter> PtrType;
|
||||
if (name == "console") {
|
||||
return PtrType(new ConsoleReporter(output_opts));
|
||||
} else if (name == "json") {
|
||||
}
|
||||
if (name == "json") {
|
||||
return PtrType(new JSONReporter());
|
||||
} else if (name == "csv") {
|
||||
}
|
||||
if (name == "csv") {
|
||||
return PtrType(new CSVReporter());
|
||||
} else {
|
||||
}
|
||||
std::cerr << "Unexpected format: '" << name << "'\n";
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_RESTORE_DEPRECATED_WARNING
|
||||
|
@ -586,13 +587,17 @@ void PrintUsageAndExit() {
|
|||
void SetDefaultTimeUnitFromFlag(const std::string& time_unit_flag) {
|
||||
if (time_unit_flag == "s") {
|
||||
return SetDefaultTimeUnit(kSecond);
|
||||
} else if (time_unit_flag == "ms") {
|
||||
}
|
||||
if (time_unit_flag == "ms") {
|
||||
return SetDefaultTimeUnit(kMillisecond);
|
||||
} else if (time_unit_flag == "us") {
|
||||
}
|
||||
if (time_unit_flag == "us") {
|
||||
return SetDefaultTimeUnit(kMicrosecond);
|
||||
} else if (time_unit_flag == "ns") {
|
||||
}
|
||||
if (time_unit_flag == "ns") {
|
||||
return SetDefaultTimeUnit(kNanosecond);
|
||||
} else if (!time_unit_flag.empty()) {
|
||||
}
|
||||
if (!time_unit_flag.empty()) {
|
||||
PrintUsageAndExit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,18 +96,18 @@ std::string FormatString(const char* msg, va_list args) {
|
|||
// currently there is no error handling for failure, so this is hack.
|
||||
BM_CHECK(ret >= 0);
|
||||
|
||||
if (ret == 0) // handle empty expansion
|
||||
if (ret == 0) { // handle empty expansion
|
||||
return {};
|
||||
else if (static_cast<size_t>(ret) < size)
|
||||
}
|
||||
if (static_cast<size_t>(ret) < size) {
|
||||
return local_buff;
|
||||
else {
|
||||
}
|
||||
// we did not provide a long enough buffer on our first attempt.
|
||||
size = static_cast<size_t>(ret) + 1; // + 1 for the null byte
|
||||
std::unique_ptr<char[]> buff(new char[size]);
|
||||
ret = vsnprintf(buff.get(), size, msg, args);
|
||||
BM_CHECK(ret > 0 && (static_cast<size_t>(ret)) < size);
|
||||
return buff.get();
|
||||
}
|
||||
}
|
||||
|
||||
std::string FormatString(const char* msg, ...) {
|
||||
|
|
|
@ -284,13 +284,14 @@ bool IsTruthyFlagValue(const std::string& value) {
|
|||
char v = value[0];
|
||||
return isalnum(v) &&
|
||||
!(v == '0' || v == 'f' || v == 'F' || v == 'n' || v == 'N');
|
||||
} else if (!value.empty()) {
|
||||
}
|
||||
if (!value.empty()) {
|
||||
std::string value_lower(value);
|
||||
std::transform(value_lower.begin(), value_lower.end(), value_lower.begin(),
|
||||
[](char c) { return static_cast<char>(::tolower(c)); });
|
||||
return !(value_lower == "false" || value_lower == "no" ||
|
||||
value_lower == "off");
|
||||
} else
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,9 +94,9 @@ std::string ExponentToPrefix(int64_t exponent, bool iec) {
|
|||
|
||||
const char* array =
|
||||
(exponent > 0 ? (iec ? kBigIECUnits : kBigSIUnits) : kSmallSIUnits);
|
||||
if (iec)
|
||||
if (iec) {
|
||||
return array[index] + std::string("i");
|
||||
else
|
||||
}
|
||||
return std::string(1, array[index]);
|
||||
}
|
||||
|
||||
|
|
|
@ -248,9 +248,8 @@ void ResultsChecker::CheckResults(std::stringstream& output) {
|
|||
if (!p.regex->Match(r.name)) {
|
||||
BM_VLOG(2) << p.regex_str << " is not matched by " << r.name << "\n";
|
||||
continue;
|
||||
} else {
|
||||
BM_VLOG(2) << p.regex_str << " is matched by " << r.name << "\n";
|
||||
}
|
||||
BM_VLOG(2) << p.regex_str << " is matched by " << r.name << "\n";
|
||||
BM_VLOG(1) << "Checking results of " << r.name << ": ... \n";
|
||||
p.fn(r);
|
||||
BM_VLOG(1) << "Checking results of " << r.name << ": OK.\n";
|
||||
|
@ -328,16 +327,18 @@ double Results::GetTime(BenchmarkTime which) const {
|
|||
BM_CHECK(unit);
|
||||
if (*unit == "ns") {
|
||||
return val * 1.e-9;
|
||||
} else if (*unit == "us") {
|
||||
}
|
||||
if (*unit == "us") {
|
||||
return val * 1.e-6;
|
||||
} else if (*unit == "ms") {
|
||||
}
|
||||
if (*unit == "ms") {
|
||||
return val * 1.e-3;
|
||||
} else if (*unit == "s") {
|
||||
}
|
||||
if (*unit == "s") {
|
||||
return val;
|
||||
} else {
|
||||
}
|
||||
BM_CHECK(1 == 0) << "unknown time unit: " << *unit;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================= //
|
||||
|
|
Loading…
Reference in New Issue