CAssetNameMap: Eliminate file-scope string allocations

This commit is contained in:
Lioncash 2020-06-11 13:21:33 -04:00
parent 9925925b6f
commit 7ce0e14e29
2 changed files with 12 additions and 7 deletions

View File

@ -1,5 +1,8 @@
#include "CAssetNameMap.h"
constexpr char gkAssetMapPath[] = "resources/gameinfo/AssetNameMap";
constexpr char gkAssetMapExt[] = "xml";
bool CAssetNameMap::LoadAssetNames(TString Path /*= ""*/)
{
if (Path.IsEmpty())
@ -194,11 +197,16 @@ void CAssetNameMap::PostLoadValidate()
TString CAssetNameMap::DefaultNameMapPath(EIDLength IDLength)
{
ASSERT(IDLength != kInvalidIDLength);
TString Suffix = (IDLength == EIDLength::k32Bit ? "32" : "64");
return gDataDir + gkAssetMapPath + Suffix + "." + gkAssetMapExt;
const char* const Suffix = (IDLength == EIDLength::k32Bit ? "32" : "64");
return gDataDir + gkAssetMapPath + Suffix + '.' + gkAssetMapExt;
}
TString CAssetNameMap::DefaultNameMapPath(EGame Game)
{
return DefaultNameMapPath( CAssetID::GameIDLength(Game) );
}
TString CAssetNameMap::GetExtension()
{
return gkAssetMapExt;
}

View File

@ -8,9 +8,6 @@
#include <map>
#include <memory>
const TString gkAssetMapPath = "resources/gameinfo/AssetNameMap";
const TString gkAssetMapExt = "xml";
class CAssetNameMap
{
struct SAssetNameInfo
@ -66,8 +63,8 @@ public:
static TString DefaultNameMapPath(EIDLength IDLength);
static TString DefaultNameMapPath(EGame Game);
inline bool IsValid() const { return mIsValid; }
inline static TString GetExtension() { return gkAssetMapExt; }
bool IsValid() const { return mIsValid; }
static TString GetExtension();
};
#endif // CASSETNAMEMAP