Fix Clang-Tidy warnings readability-else-after-return (#1528)

This commit is contained in:
SunBlack 2023-01-16 13:28:48 +01:00 committed by GitHub
parent a3235d7b69
commit cfbc94960f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 38 deletions

View File

@ -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") {
return PtrType(new JSONReporter());
} else if (name == "csv") {
return PtrType(new CSVReporter());
} else {
std::cerr << "Unexpected format: '" << name << "'\n";
std::exit(1);
}
if (name == "json") {
return PtrType(new JSONReporter());
}
if (name == "csv") {
return PtrType(new CSVReporter());
}
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();
}
}

View File

@ -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)
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();
}
if (static_cast<size_t>(ret) < size) {
return local_buff;
}
// 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, ...) {

View File

@ -284,14 +284,15 @@ 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;
}
return true;
}
} // end namespace benchmark

View File

@ -94,10 +94,10 @@ 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]);
}
return std::string(1, array[index]);
}
std::string ToBinaryStringFullySpecified(double value, double threshold,

View File

@ -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") {
return val * 1.e-6;
} else if (*unit == "ms") {
return val * 1.e-3;
} else if (*unit == "s") {
return val;
} else {
BM_CHECK(1 == 0) << "unknown time unit: " << *unit;
return 0;
}
if (*unit == "us") {
return val * 1.e-6;
}
if (*unit == "ms") {
return val * 1.e-3;
}
if (*unit == "s") {
return val;
}
BM_CHECK(1 == 0) << "unknown time unit: " << *unit;
return 0;
}
// ========================================================================= //