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
parent ce1a122618
commit 90fe4e5bea
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;
}
std::vector<String> ApplyRule::GetTargetTypes(const String& sourceType)
const std::vector<String>& ApplyRule::GetTargetTypes(const String& sourceType)
{
auto it = m_Types.find(sourceType);
if (it == m_Types.end())
return std::vector<String>();
if (it == m_Types.end()) {
static const std::vector<String> noTypes;
return noTypes;
}
return it->second;
}

View File

@ -43,7 +43,7 @@ public:
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
static bool IsValidSourceType(const String& sourceType);
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);

View File

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