From e23dfbd8db884b833879135b351c18f03c72fb85 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 1 Sep 2019 03:10:24 -0400 Subject: [PATCH] CStringTable: Use std::array instead of std::vector Gets rid of a static constructor, as well as a few heap allocations --- Runtime/GuiSys/CStringTable.cpp | 18 ++++++++++++------ Runtime/GuiSys/CStringTable.hpp | 1 - 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Runtime/GuiSys/CStringTable.cpp b/Runtime/GuiSys/CStringTable.cpp index 9638934cc..28ee609bb 100644 --- a/Runtime/GuiSys/CStringTable.cpp +++ b/Runtime/GuiSys/CStringTable.cpp @@ -1,11 +1,17 @@ -#include "CStringTable.hpp" -#include "CToken.hpp" +#include "Runtime/GuiSys/CStringTable.hpp" + +#include + +#include "Runtime/CToken.hpp" namespace urde { -const std::vector CStringTable::skLanguages = {FOURCC('ENGL'), FOURCC('FREN'), FOURCC('GERM'), FOURCC('SPAN'), - FOURCC('ITAL'), FOURCC('DUTC'), FOURCC('JAPN')}; +namespace { +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); } @@ -64,7 +70,7 @@ const char16_t* CStringTable::GetString(s32 str) const { return reinterpret_cast(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&, CObjectReference* selfRef) { diff --git a/Runtime/GuiSys/CStringTable.hpp b/Runtime/GuiSys/CStringTable.hpp index 2915d986b..e949fff81 100644 --- a/Runtime/GuiSys/CStringTable.hpp +++ b/Runtime/GuiSys/CStringTable.hpp @@ -5,7 +5,6 @@ namespace urde { class CStringTable { - static const std::vector skLanguages; static FourCC mCurrentLanguage; u32 x0_stringCount = 0; std::unique_ptr x4_data = 0;