CStringTable: Use std::array instead of std::vector

Gets rid of a static constructor, as well as a few heap allocations
This commit is contained in:
Lioncash 2019-09-01 03:10:24 -04:00
parent 484a6b0cdf
commit e23dfbd8db
2 changed files with 12 additions and 7 deletions

View File

@ -1,11 +1,17 @@
#include "CStringTable.hpp" #include "Runtime/GuiSys/CStringTable.hpp"
#include "CToken.hpp"
#include <array>
#include "Runtime/CToken.hpp"
namespace urde { namespace urde {
const std::vector<FourCC> CStringTable::skLanguages = {FOURCC('ENGL'), FOURCC('FREN'), FOURCC('GERM'), FOURCC('SPAN'), namespace {
FOURCC('ITAL'), FOURCC('DUTC'), FOURCC('JAPN')}; constexpr std::array languages{
FOURCC('ENGL'), FOURCC('FREN'), FOURCC('GERM'), FOURCC('SPAN'), FOURCC('ITAL'), FOURCC('DUTC'), FOURCC('JAPN'),
};
} // Anonymous namespace
FourCC CStringTable::mCurrentLanguage = CStringTable::skLanguages[0]; FourCC CStringTable::mCurrentLanguage = languages[0];
CStringTable::CStringTable(CInputStream& in) { LoadStringTable(in); } CStringTable::CStringTable(CInputStream& in) { LoadStringTable(in); }
@ -64,7 +70,7 @@ const char16_t* CStringTable::GetString(s32 str) const {
return reinterpret_cast<char16_t*>(x4_data.get() + off); return reinterpret_cast<char16_t*>(x4_data.get() + off);
} }
void CStringTable::SetLanguage(s32 lang) { mCurrentLanguage = skLanguages[lang]; } void CStringTable::SetLanguage(s32 lang) { mCurrentLanguage = languages[lang]; }
CFactoryFnReturn FStringTableFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer&, CFactoryFnReturn FStringTableFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer&,
CObjectReference* selfRef) { CObjectReference* selfRef) {

View File

@ -5,7 +5,6 @@
namespace urde { namespace urde {
class CStringTable { class CStringTable {
static const std::vector<FourCC> skLanguages;
static FourCC mCurrentLanguage; static FourCC mCurrentLanguage;
u32 x0_stringCount = 0; u32 x0_stringCount = 0;
std::unique_ptr<u8[]> x4_data = 0; std::unique_ptr<u8[]> x4_data = 0;