ApplyRule::GetTargetTypes(): return by const ref not to malloc()

This commit is contained in:
Alexander A. Klimov 2022-10-19 13:42:33 +02:00 committed by Yonas Habteab
parent cdd531445a
commit 7f50955674
3 changed files with 7 additions and 5 deletions

View File

@ -111,12 +111,14 @@ bool ApplyRule::IsValidTargetType(const String& sourceType, const String& target
return false; return false;
} }
std::vector<String> ApplyRule::GetTargetTypes(const String& sourceType) const std::vector<String>& ApplyRule::GetTargetTypes(const String& sourceType)
{ {
auto it = m_Types.find(sourceType); auto it = m_Types.find(sourceType);
if (it == m_Types.end()) if (it == m_Types.end()) {
return std::vector<String>(); static const std::vector<String> noTypes;
return noTypes;
}
return it->second; return it->second;
} }

View File

@ -43,7 +43,7 @@ public:
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes); static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
static bool IsValidSourceType(const String& sourceType); static bool IsValidSourceType(const String& sourceType);
static bool IsValidTargetType(const String& sourceType, const String& targetType); static bool IsValidTargetType(const String& sourceType, const String& targetType);
static std::vector<String> GetTargetTypes(const String& sourceType); static const std::vector<String>& GetTargetTypes(const String& sourceType);
static void CheckMatches(bool silent); static void CheckMatches(bool silent);

View File

@ -1165,7 +1165,7 @@ apply:
if (!ApplyRule::IsValidTargetType(type, target)) { if (!ApplyRule::IsValidTargetType(type, target)) {
if (target == "") { if (target == "") {
std::vector<String> types = ApplyRule::GetTargetTypes(type); auto& types (ApplyRule::GetTargetTypes(type));
String typeNames; String typeNames;
for (std::vector<String>::size_type i = 0; i < types.size(); i++) { for (std::vector<String>::size_type i = 0; i < types.size(); i++) {