Source: Improve some code readability and efficiency
- Replace raw loop with STL find algorithm for improved efficiency - Update functions for enhanced readability and understandabilitystage/master/nightly/2023/05/20
parent
f64a774b49
commit
8c066045ec
|
@ -17,14 +17,13 @@ void cmExternalMakefileProjectGenerator::EnableLanguage(
|
|||
std::string cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
|
||||
const std::string& globalGenerator, const std::string& extraGenerator)
|
||||
{
|
||||
std::string fullName;
|
||||
if (!globalGenerator.empty()) {
|
||||
if (!extraGenerator.empty()) {
|
||||
fullName = cmStrCat(extraGenerator, " - ");
|
||||
}
|
||||
fullName += globalGenerator;
|
||||
if (globalGenerator.empty()) {
|
||||
return {};
|
||||
}
|
||||
return fullName;
|
||||
if (extraGenerator.empty()) {
|
||||
return globalGenerator;
|
||||
}
|
||||
return cmStrCat(extraGenerator, " - ", globalGenerator);
|
||||
}
|
||||
|
||||
bool cmExternalMakefileProjectGenerator::Open(
|
||||
|
|
|
@ -18,51 +18,38 @@
|
|||
|
||||
MessageType cmMessenger::ConvertMessageType(MessageType t) const
|
||||
{
|
||||
bool warningsAsErrors;
|
||||
|
||||
if (t == MessageType::AUTHOR_WARNING || t == MessageType::AUTHOR_ERROR) {
|
||||
warningsAsErrors = this->GetDevWarningsAsErrors();
|
||||
if (warningsAsErrors && t == MessageType::AUTHOR_WARNING) {
|
||||
t = MessageType::AUTHOR_ERROR;
|
||||
} else if (!warningsAsErrors && t == MessageType::AUTHOR_ERROR) {
|
||||
t = MessageType::AUTHOR_WARNING;
|
||||
}
|
||||
} else if (t == MessageType::DEPRECATION_WARNING ||
|
||||
t == MessageType::DEPRECATION_ERROR) {
|
||||
warningsAsErrors = this->GetDeprecatedWarningsAsErrors();
|
||||
if (warningsAsErrors && t == MessageType::DEPRECATION_WARNING) {
|
||||
t = MessageType::DEPRECATION_ERROR;
|
||||
} else if (!warningsAsErrors && t == MessageType::DEPRECATION_ERROR) {
|
||||
t = MessageType::DEPRECATION_WARNING;
|
||||
if (this->GetDevWarningsAsErrors()) {
|
||||
return MessageType::AUTHOR_ERROR;
|
||||
}
|
||||
return MessageType::AUTHOR_WARNING;
|
||||
}
|
||||
if (t == MessageType::DEPRECATION_WARNING ||
|
||||
t == MessageType::DEPRECATION_ERROR) {
|
||||
if (this->GetDeprecatedWarningsAsErrors()) {
|
||||
return MessageType::DEPRECATION_ERROR;
|
||||
}
|
||||
return MessageType::DEPRECATION_WARNING;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
bool cmMessenger::IsMessageTypeVisible(MessageType t) const
|
||||
{
|
||||
bool isVisible = true;
|
||||
|
||||
if (t == MessageType::DEPRECATION_ERROR) {
|
||||
if (!this->GetDeprecatedWarningsAsErrors()) {
|
||||
isVisible = false;
|
||||
}
|
||||
} else if (t == MessageType::DEPRECATION_WARNING) {
|
||||
if (this->GetSuppressDeprecatedWarnings()) {
|
||||
isVisible = false;
|
||||
}
|
||||
} else if (t == MessageType::AUTHOR_ERROR) {
|
||||
if (!this->GetDevWarningsAsErrors()) {
|
||||
isVisible = false;
|
||||
}
|
||||
} else if (t == MessageType::AUTHOR_WARNING) {
|
||||
if (this->GetSuppressDevWarnings()) {
|
||||
isVisible = false;
|
||||
}
|
||||
return this->GetDeprecatedWarningsAsErrors();
|
||||
}
|
||||
if (t == MessageType::DEPRECATION_WARNING) {
|
||||
return !this->GetSuppressDeprecatedWarnings();
|
||||
}
|
||||
if (t == MessageType::AUTHOR_ERROR) {
|
||||
return this->GetDevWarningsAsErrors();
|
||||
}
|
||||
if (t == MessageType::AUTHOR_WARNING) {
|
||||
return !this->GetSuppressDevWarnings();
|
||||
}
|
||||
|
||||
return isVisible;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool printMessagePreamble(MessageType t, std::ostream& msg)
|
||||
|
|
|
@ -101,11 +101,13 @@ cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
|
|||
bool cmState::StringToCacheEntryType(const std::string& s,
|
||||
cmStateEnums::CacheEntryType& type)
|
||||
{
|
||||
for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) {
|
||||
if (s == cmCacheEntryTypes[i]) {
|
||||
type = static_cast<cmStateEnums::CacheEntryType>(i);
|
||||
return true;
|
||||
}
|
||||
// NOLINTNEXTLINE(readability-qualified-auto)
|
||||
auto const entry =
|
||||
std::find(cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(), s);
|
||||
if (entry != cmCacheEntryTypes.end()) {
|
||||
type = static_cast<cmStateEnums::CacheEntryType>(
|
||||
entry - cmCacheEntryTypes.begin());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue