getRecNameString now constexpr

getTypeDescription uses a static constexpr variable so we don't return ref to temp memory.
macos_ci
florent.teppe 2 years ago
parent 25bbaa2343
commit 04e026c53f

@ -142,7 +142,10 @@ namespace MWWorld
std::string_view getTypeDescription() const override
{
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
return X::getRecordType();
}

@ -332,17 +332,16 @@ namespace ESM
return RecName & sEsm4RecnameFlag;
}
inline FixedString<6> getRecNameString(ESM::RecNameInts recName)
constexpr inline FixedString<6> getRecNameString(ESM::RecNameInts recName)
{
ESM::FixedString<6> name;
name.assign("");
name.mData[5] = '\0';
ESM::NAME fourCCName(recName & ~ESM::sEsm4RecnameFlag);
for (int i = 0; i < 4; i++)
name.mData[i] = fourCCName.mData[i];
if (ESM::isESM4Rec(recName))
{
name.mData[4] = '4';
}
name.mData[4] = ESM::isESM4Rec(recName) ? '4' : '\0';
return name;
}

Loading…
Cancel
Save