CVar: Remove redundant const return for toLiteral() and toWideLiteral()

This can actually inhibit copy elision
This commit is contained in:
Lioncash 2019-08-20 10:15:10 -04:00
parent 3795e0e72c
commit b9e5417a94
2 changed files with 8 additions and 6 deletions

View File

@ -70,8 +70,8 @@ public:
float toFloat(bool* isValid = nullptr) const;
bool toBoolean(bool* isValid = nullptr) const;
int toInteger(bool* isValid = nullptr) const;
const std::wstring toWideLiteral(bool* isValid = nullptr) const;
const std::string toLiteral(bool* isValid = nullptr) const;
std::wstring toWideLiteral(bool* isValid = nullptr) const;
std::string toLiteral(bool* isValid = nullptr) const;
bool fromVec4f(const atVec4f& val);
bool fromFloat(float val);

View File

@ -191,23 +191,25 @@ int CVar::toInteger(bool* isValid) const {
return strtol(m_value.c_str(), nullptr, 0);
}
const std::string CVar::toLiteral(bool* isValid) const {
std::string CVar::toLiteral(bool* isValid) const {
if (m_type != EType::Literal && (com_developer && com_developer->toBoolean())) {
if (isValid != nullptr)
*isValid = false;
} else if (isValid != nullptr)
} else if (isValid != nullptr) {
*isValid = true;
}
// Even if it's not a literal, it's still safe to return
return m_value;
}
const std::wstring CVar::toWideLiteral(bool* isValid) const {
std::wstring CVar::toWideLiteral(bool* isValid) const {
if (m_type != EType::Literal && (com_developer && com_developer->toBoolean())) {
if (isValid != nullptr)
*isValid = false;
} else if (isValid != nullptr)
} else if (isValid != nullptr) {
*isValid = true;
}
// Even if it's not a literal, it's still safe to return
return hecl::UTF8ToWide(m_value);