fix(Core): Memleaks fixes - Part II. (#5760)

This commit is contained in:
UltraNix
2021-05-14 10:15:45 +02:00
committed by GitHub
parent 1b6c2004ce
commit 8dd58ebb5b
19 changed files with 138 additions and 127 deletions

View File

@@ -361,14 +361,14 @@ ObjectMgr* ObjectMgr::instance()
return &instance;
}
void ObjectMgr::AddLocaleString(std::string const& s, LocaleConstant locale, StringVector& data)
void ObjectMgr::AddLocaleString(std::string&& s, LocaleConstant locale, StringVector& data)
{
if (!s.empty())
{
if (data.size() <= size_t(locale))
data.resize(locale + 1);
data[locale] = s;
data[locale] = std::move(s);
}
}
@@ -387,18 +387,15 @@ void ObjectMgr::LoadCreatureLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
std::string Title = fields[3].GetString();
uint32 ID = fields[0].GetUInt32();
CreatureLocale& data = _creatureLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
AddLocaleString(Name, locale, data.Name);
AddLocaleString(Title, locale, data.Title);
CreatureLocale& data = _creatureLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Name);
AddLocaleString(fields[3].GetString(), locale, data.Title);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %lu Creature Locale strings in %u ms", (unsigned long)_creatureLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -420,20 +417,16 @@ void ObjectMgr::LoadGossipMenuItemsLocales()
{
Field* fields = result->Fetch();
uint16 MenuID = fields[0].GetUInt16();
uint16 OptionID = fields[1].GetUInt16();
std::string LocaleName = fields[2].GetString();
uint16 MenuID = fields[0].GetUInt16();
uint16 OptionID = fields[1].GetUInt16();
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[2].GetString());
if (locale == LOCALE_enUS)
continue;
std::string OptionText = fields[3].GetString();
std::string BoxText = fields[4].GetString();
GossipMenuItemsLocale& data = _gossipMenuItemsLocaleStore[MAKE_PAIR32(MenuID, OptionID)];
AddLocaleString(OptionText, locale, data.OptionText);
AddLocaleString(BoxText, locale, data.BoxText);
AddLocaleString(fields[3].GetString(), locale, data.OptionText);
AddLocaleString(fields[4].GetString(), locale, data.BoxText);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Gossip Menu Option Locale strings in %u ms", (uint32)_gossipMenuItemsLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -455,16 +448,14 @@ void ObjectMgr::LoadPointOfInterestLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
uint32 ID = fields[0].GetUInt32();
PointOfInterestLocale& data = _pointOfInterestLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
AddLocaleString(Name, locale, data.Name);
PointOfInterestLocale& data = _pointOfInterestLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Name);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Points Of Interest Locale strings in %u ms", (uint32)_pointOfInterestLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -2380,18 +2371,15 @@ void ObjectMgr::LoadItemLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
std::string Description = fields[3].GetString();
uint32 ID = fields[0].GetUInt32();
ItemLocale& data = _itemLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
AddLocaleString(Name, locale, data.Name);
AddLocaleString(Description, locale, data.Description);
ItemLocale& data = _itemLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Name);
AddLocaleString(fields[3].GetString(), locale, data.Description);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Item Locale strings in %u ms", (uint32)_itemLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -3006,16 +2994,14 @@ void ObjectMgr::LoadItemSetNameLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
uint32 ID = fields[0].GetUInt32();
ItemSetNameLocale& data = _itemSetNameLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
AddLocaleString(Name, locale, data.Name);
ItemSetNameLocale& data = _itemSetNameLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Name);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Item Set Name Locale strings in %u ms", uint32(_itemSetNameLocaleStore.size()), GetMSTimeDiffToNow(oldMSTime));
@@ -4737,14 +4723,13 @@ void ObjectMgr::LoadQuestLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
uint32 ID = fields[0].GetUInt32();
QuestLocale& data = _questLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
QuestLocale& data = _questLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Title);
AddLocaleString(fields[3].GetString(), locale, data.Details);
AddLocaleString(fields[4].GetString(), locale, data.Objectives);
@@ -5362,14 +5347,14 @@ void ObjectMgr::LoadPageTextLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Text = fields[2].GetString();
uint32 ID = fields[0].GetUInt32();
PageTextLocale& data = _pageTextLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
AddLocaleString(Text, locale, data.Text);
PageTextLocale& data = _pageTextLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Text);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Page Text Locale strings in %u ms", (uint32)_pageTextLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -5613,14 +5598,13 @@ void ObjectMgr::LoadNpcTextLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
uint32 ID = fields[0].GetUInt32();
NpcTextLocale& data = _npcTextLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
NpcTextLocale& data = _npcTextLocaleStore[ID];
for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
{
AddLocaleString(fields[2 + i * 2].GetString(), locale, data.Text_0[i]);
@@ -6498,18 +6482,15 @@ void ObjectMgr::LoadGameObjectLocales()
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
std::string CastBarCaption = fields[3].GetString();
uint32 ID = fields[0].GetUInt32();
GameObjectLocale& data = _gameObjectLocaleStore[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
AddLocaleString(Name, locale, data.Name);
AddLocaleString(CastBarCaption, locale, data.CastBarCaption);
GameObjectLocale& data = _gameObjectLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Name);
AddLocaleString(fields[3].GetString(), locale, data.CastBarCaption);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Gameobject Locale strings in %u ms", (uint32)_gameObjectLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -8800,10 +8781,7 @@ void ObjectMgr::LoadBroadcastTextLocales()
{
Field* fields = result->Fetch();
uint32 id = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string MaleText = fields[2].GetString();
std::string FemaleText = fields[3].GetString();
uint32 id = fields[0].GetUInt32();
BroadcastTextContainer::iterator bct = _broadcastTextStore.find(id);
if (bct == _broadcastTextStore.end())
@@ -8812,12 +8790,12 @@ void ObjectMgr::LoadBroadcastTextLocales()
continue;
}
LocaleConstant locale = GetLocaleByName(LocaleName);
LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS)
continue;
AddLocaleString(MaleText, locale, bct->second.MaleText);
AddLocaleString(FemaleText, locale, bct->second.FemaleText);
AddLocaleString(fields[2].GetString(), locale, bct->second.MaleText);
AddLocaleString(fields[3].GetString(), locale, bct->second.FemaleText);
} while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Broadcast Text Locales in %u ms", uint32(_broadcastTextStore.size()), GetMSTimeDiffToNow(oldMSTime));