1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 11:18:40 +08:00

Source: Improve some code readability and efficiency

- Replace raw loop with STL find algorithm for improved efficiency
- Update functions for enhanced readability and understandability
This commit is contained in:
Meekness Adesina
2023-05-18 22:11:41 +01:00
committed by Brad King
parent f64a774b49
commit 8c066045ec
3 changed files with 34 additions and 46 deletions

View File

@@ -17,14 +17,13 @@ void cmExternalMakefileProjectGenerator::EnableLanguage(
std::string cmExternalMakefileProjectGenerator::CreateFullGeneratorName( std::string cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
const std::string& globalGenerator, const std::string& extraGenerator) const std::string& globalGenerator, const std::string& extraGenerator)
{ {
std::string fullName; if (globalGenerator.empty()) {
if (!globalGenerator.empty()) { return {};
if (!extraGenerator.empty()) {
fullName = cmStrCat(extraGenerator, " - ");
} }
fullName += globalGenerator; if (extraGenerator.empty()) {
return globalGenerator;
} }
return fullName; return cmStrCat(extraGenerator, " - ", globalGenerator);
} }
bool cmExternalMakefileProjectGenerator::Open( bool cmExternalMakefileProjectGenerator::Open(

View File

@@ -18,51 +18,38 @@
MessageType cmMessenger::ConvertMessageType(MessageType t) const MessageType cmMessenger::ConvertMessageType(MessageType t) const
{ {
bool warningsAsErrors;
if (t == MessageType::AUTHOR_WARNING || t == MessageType::AUTHOR_ERROR) { if (t == MessageType::AUTHOR_WARNING || t == MessageType::AUTHOR_ERROR) {
warningsAsErrors = this->GetDevWarningsAsErrors(); if (this->GetDevWarningsAsErrors()) {
if (warningsAsErrors && t == MessageType::AUTHOR_WARNING) { return MessageType::AUTHOR_ERROR;
t = MessageType::AUTHOR_ERROR;
} else if (!warningsAsErrors && t == MessageType::AUTHOR_ERROR) {
t = MessageType::AUTHOR_WARNING;
} }
} else if (t == MessageType::DEPRECATION_WARNING || return MessageType::AUTHOR_WARNING;
}
if (t == MessageType::DEPRECATION_WARNING ||
t == MessageType::DEPRECATION_ERROR) { t == MessageType::DEPRECATION_ERROR) {
warningsAsErrors = this->GetDeprecatedWarningsAsErrors(); if (this->GetDeprecatedWarningsAsErrors()) {
if (warningsAsErrors && t == MessageType::DEPRECATION_WARNING) { return MessageType::DEPRECATION_ERROR;
t = MessageType::DEPRECATION_ERROR;
} else if (!warningsAsErrors && t == MessageType::DEPRECATION_ERROR) {
t = MessageType::DEPRECATION_WARNING;
} }
return MessageType::DEPRECATION_WARNING;
} }
return t; return t;
} }
bool cmMessenger::IsMessageTypeVisible(MessageType t) const bool cmMessenger::IsMessageTypeVisible(MessageType t) const
{ {
bool isVisible = true;
if (t == MessageType::DEPRECATION_ERROR) { if (t == MessageType::DEPRECATION_ERROR) {
if (!this->GetDeprecatedWarningsAsErrors()) { return this->GetDeprecatedWarningsAsErrors();
isVisible = false;
} }
} else if (t == MessageType::DEPRECATION_WARNING) { if (t == MessageType::DEPRECATION_WARNING) {
if (this->GetSuppressDeprecatedWarnings()) { return !this->GetSuppressDeprecatedWarnings();
isVisible = false;
} }
} else if (t == MessageType::AUTHOR_ERROR) { if (t == MessageType::AUTHOR_ERROR) {
if (!this->GetDevWarningsAsErrors()) { return this->GetDevWarningsAsErrors();
isVisible = false;
}
} else if (t == MessageType::AUTHOR_WARNING) {
if (this->GetSuppressDevWarnings()) {
isVisible = false;
} }
if (t == MessageType::AUTHOR_WARNING) {
return !this->GetSuppressDevWarnings();
} }
return isVisible; return true;
} }
static bool printMessagePreamble(MessageType t, std::ostream& msg) static bool printMessagePreamble(MessageType t, std::ostream& msg)

View File

@@ -101,12 +101,14 @@ cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
bool cmState::StringToCacheEntryType(const std::string& s, bool cmState::StringToCacheEntryType(const std::string& s,
cmStateEnums::CacheEntryType& type) cmStateEnums::CacheEntryType& type)
{ {
for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) { // NOLINTNEXTLINE(readability-qualified-auto)
if (s == cmCacheEntryTypes[i]) { auto const entry =
type = static_cast<cmStateEnums::CacheEntryType>(i); std::find(cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(), s);
if (entry != cmCacheEntryTypes.end()) {
type = static_cast<cmStateEnums::CacheEntryType>(
entry - cmCacheEntryTypes.begin());
return true; return true;
} }
}
return false; return false;
} }