mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-02 03:36:40 +00:00
getRecNameString now constexpr
getTypeDescription uses a static constexpr variable so we don't return ref to temp memory.
This commit is contained in:
parent
25bbaa2343
commit
04e026c53f
2 changed files with 9 additions and 7 deletions
|
@ -142,7 +142,10 @@ namespace MWWorld
|
||||||
std::string_view getTypeDescription() const override
|
std::string_view getTypeDescription() const override
|
||||||
{
|
{
|
||||||
if constexpr (ESM::isESM4Rec(X::sRecordId))
|
if constexpr (ESM::isESM4Rec(X::sRecordId))
|
||||||
return ESM::getRecNameString(X::sRecordId).toStringView();
|
{
|
||||||
|
static constexpr ESM::FixedString<6> name = ESM::getRecNameString(X::sRecordId);
|
||||||
|
return name.toStringView();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return X::getRecordType();
|
return X::getRecordType();
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,17 +332,16 @@ namespace ESM
|
||||||
return RecName & sEsm4RecnameFlag;
|
return RecName & sEsm4RecnameFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline FixedString<6> getRecNameString(ESM::RecNameInts recName)
|
constexpr inline FixedString<6> getRecNameString(ESM::RecNameInts recName)
|
||||||
{
|
{
|
||||||
ESM::FixedString<6> name;
|
ESM::FixedString<6> name;
|
||||||
name.assign("");
|
name.mData[5] = '\0';
|
||||||
|
|
||||||
ESM::NAME fourCCName(recName & ~ESM::sEsm4RecnameFlag);
|
ESM::NAME fourCCName(recName & ~ESM::sEsm4RecnameFlag);
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
name.mData[i] = fourCCName.mData[i];
|
name.mData[i] = fourCCName.mData[i];
|
||||||
if (ESM::isESM4Rec(recName))
|
|
||||||
{
|
name.mData[4] = ESM::isESM4Rec(recName) ? '4' : '\0';
|
||||||
name.mData[4] = '4';
|
|
||||||
}
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue