Mod container-anti-pattern

Finds when temporary containers are being created needlessly.
These cases are usually easy to fix by using iterators,
avoiding memory allocations.

And mod to return on first true

can we test if the Elements collection reload faster or not?
This commit is contained in:
Simon De Backer 2020-11-01 18:44:14 +01:00
parent 41c7cde8ca
commit 1b10fe3b7f

View File

@ -229,28 +229,25 @@ bool NamesList::operator==(const NamesList &nl) const
}
/**
Return the adequate name regarding the current system locale.
By order of preference, this function chooses:
- the name in the system language
- the English name
- the provided fallback name if non-empty
- the first language encountered in the list
- an empty string
@param fallback_name name to be returned when no adequate name has been found
@return The adequate name regarding the current system locale.
* @brief NamesList::name
* Return the adequate name regarding the current system locale.
* By order of preference, this function chooses:
* - the name in the system language
* - the English name
* - the provided fallback name if non-empty
* - the first language encountered in the list
* - an empty string
* @param fallback_name
* name to be returned when no adequate name has been found
* @return The adequate name regarding the current system locale.
*/
QString NamesList::name(const QString &fallback_name) const
{
QString system_language = QETApp::langFromSetting();
QString returned_name;
if (!hash_names[system_language].isEmpty()) {
returned_name = hash_names[system_language];
} else if (!hash_names["en"].isEmpty()) {
returned_name = hash_names["en"];
} else if (!fallback_name.isEmpty()) {
returned_name = fallback_name;
} else if (hash_names.count()) {
returned_name = hash_names.value(hash_names.keys().first());
}
return(returned_name);
if (! hash_names[system_language].isEmpty())
return (hash_names[system_language]);
if (! hash_names["en"].isEmpty()) return (hash_names["en"]);
if (! fallback_name.isEmpty()) return (fallback_name);
if (hash_names.count()) return (hash_names.begin().value());
return (QString(""));
}