refactor(Core/Misc): Use emplace_back instead of push_back to avoid extra copy/m… (#20114)
refactor: Use emplace_back instead of push_back to avoid extra copy/move operations
This commit is contained in:
@@ -277,7 +277,7 @@ void PetAI::UpdateAI(uint32 diff)
|
|||||||
{
|
{
|
||||||
if (CanAttack(target) && spell->CanAutoCast(target))
|
if (CanAttack(target) && spell->CanAutoCast(target))
|
||||||
{
|
{
|
||||||
targetSpellStore.push_back(std::make_pair(target, spell));
|
targetSpellStore.emplace_back(target, spell);
|
||||||
spellUsed = true;
|
spellUsed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,7 +295,7 @@ void PetAI::UpdateAI(uint32 diff)
|
|||||||
|
|
||||||
if (spell->CanAutoCast(ally))
|
if (spell->CanAutoCast(ally))
|
||||||
{
|
{
|
||||||
targetSpellStore.push_back(std::make_pair(ally, spell));
|
targetSpellStore.emplace_back(ally, spell);
|
||||||
spellUsed = true;
|
spellUsed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -310,7 +310,7 @@ void PetAI::UpdateAI(uint32 diff)
|
|||||||
{
|
{
|
||||||
Spell* spell = new Spell(me, spellInfo, TRIGGERED_NONE);
|
Spell* spell = new Spell(me, spellInfo, TRIGGERED_NONE);
|
||||||
if (spell->CanAutoCast(me->GetVictim()))
|
if (spell->CanAutoCast(me->GetVictim()))
|
||||||
targetSpellStore.push_back(std::make_pair(me->GetVictim(), spell));
|
targetSpellStore.emplace_back(me->GetVictim(), spell);
|
||||||
else
|
else
|
||||||
delete spell;
|
delete spell;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace AddonMgr
|
|||||||
std::string name = fields[0].Get<std::string>();
|
std::string name = fields[0].Get<std::string>();
|
||||||
uint32 crc = fields[1].Get<uint32>();
|
uint32 crc = fields[1].Get<uint32>();
|
||||||
|
|
||||||
m_knownAddons.push_back(SavedAddon(name, crc));
|
m_knownAddons.emplace_back(name, crc);
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
@@ -76,13 +76,12 @@ namespace AddonMgr
|
|||||||
{
|
{
|
||||||
Field* fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
|
|
||||||
BannedAddon addon{};
|
uint32 Id = fields[0].Get<uint32>() + offset;
|
||||||
addon.Id = fields[0].Get<uint32>() + offset;
|
std::array<uint8, 16> NameMD5 = Acore::Crypto::MD5::GetDigestOf(fields[1].Get<std::string>());
|
||||||
addon.Timestamp = uint32(fields[3].Get<uint64>());
|
std::array<uint8, 16> VersionMD5 = Acore::Crypto::MD5::GetDigestOf(fields[2].Get<std::string>());
|
||||||
addon.NameMD5 = Acore::Crypto::MD5::GetDigestOf(fields[1].Get<std::string>());
|
uint32 Timestamp = uint32(fields[3].Get<uint64>());
|
||||||
addon.VersionMD5 = Acore::Crypto::MD5::GetDigestOf(fields[2].Get<std::string>());
|
|
||||||
|
|
||||||
m_bannedAddons.emplace_back(addon);
|
m_bannedAddons.emplace_back(Id, NameMD5, VersionMD5, Timestamp);
|
||||||
|
|
||||||
++count2;
|
++count2;
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
@@ -94,16 +93,14 @@ namespace AddonMgr
|
|||||||
|
|
||||||
void SaveAddon(AddonInfo const& addon)
|
void SaveAddon(AddonInfo const& addon)
|
||||||
{
|
{
|
||||||
std::string name = addon.Name;
|
|
||||||
|
|
||||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ADDON);
|
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ADDON);
|
||||||
|
|
||||||
stmt->SetData(0, name);
|
stmt->SetData(0, addon.Name);
|
||||||
stmt->SetData(1, addon.CRC);
|
stmt->SetData(1, addon.CRC);
|
||||||
|
|
||||||
CharacterDatabase.Execute(stmt);
|
CharacterDatabase.Execute(stmt);
|
||||||
|
|
||||||
m_knownAddons.push_back(SavedAddon(addon.Name, addon.CRC));
|
m_knownAddons.emplace_back(addon.Name, addon.CRC);
|
||||||
}
|
}
|
||||||
|
|
||||||
SavedAddon const* GetAddonInfo(const std::string& name)
|
SavedAddon const* GetAddonInfo(const std::string& name)
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ struct AddonInfo
|
|||||||
|
|
||||||
struct SavedAddon
|
struct SavedAddon
|
||||||
{
|
{
|
||||||
SavedAddon(std::string name, uint32 crc) : Name(std::move(name))
|
SavedAddon(std::string name, uint32 crc) : Name(std::move(name)), CRC(crc) {}
|
||||||
{
|
|
||||||
CRC = crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Name;
|
std::string Name;
|
||||||
uint32 CRC;
|
uint32 CRC;
|
||||||
@@ -49,6 +46,9 @@ struct SavedAddon
|
|||||||
|
|
||||||
struct BannedAddon
|
struct BannedAddon
|
||||||
{
|
{
|
||||||
|
BannedAddon(uint32 id, std::array<uint8, 16> const& nameMD5, std::array<uint8, 16> const& versionMD5, uint32 timestamp)
|
||||||
|
: Id(id), NameMD5(nameMD5), VersionMD5(versionMD5), Timestamp(timestamp) {}
|
||||||
|
|
||||||
uint32 Id;
|
uint32 Id;
|
||||||
std::array<uint8, 16> NameMD5;
|
std::array<uint8, 16> NameMD5;
|
||||||
std::array<uint8, 16> VersionMD5;
|
std::array<uint8, 16> VersionMD5;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ void ChannelMgr::LoadChannels()
|
|||||||
if (!Utf8toWStr(channelName, channelWName))
|
if (!Utf8toWStr(channelName, channelWName))
|
||||||
{
|
{
|
||||||
LOG_ERROR("server.loading", "Failed to load channel '{}' from database - invalid utf8 sequence? Deleted.", channelName);
|
LOG_ERROR("server.loading", "Failed to load channel '{}' from database - invalid utf8 sequence? Deleted.", channelName);
|
||||||
toDelete.push_back({ channelName, team });
|
toDelete.emplace_back(channelName, team);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ void ChannelMgr::LoadChannels()
|
|||||||
if (!mgr)
|
if (!mgr)
|
||||||
{
|
{
|
||||||
LOG_ERROR("server.loading", "Failed to load custom chat channel '{}' from database - invalid team {}. Deleted.", channelName, team);
|
LOG_ERROR("server.loading", "Failed to load custom chat channel '{}' from database - invalid team {}. Deleted.", channelName, team);
|
||||||
toDelete.push_back({ channelName, team });
|
toDelete.emplace_back(channelName, team);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ void LootItemStorage::LoadStorageFromDB()
|
|||||||
Field* fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
|
|
||||||
StoredLootItemList& itemList = lootItemStore[ObjectGuid::Create<HighGuid::Item>(fields[0].Get<uint32>())];
|
StoredLootItemList& itemList = lootItemStore[ObjectGuid::Create<HighGuid::Item>(fields[0].Get<uint32>())];
|
||||||
itemList.push_back(StoredLootItem(fields[1].Get<uint32>(), fields[2].Get<uint32>(), fields[3].Get<uint32>(), fields[4].Get<int32>(), fields[5].Get<uint32>(), fields[6].Get<bool>(),
|
itemList.emplace_back(fields[1].Get<uint32>(), fields[2].Get<uint32>(), fields[3].Get<uint32>(), fields[4].Get<int32>(), fields[5].Get<uint32>(), fields[6].Get<bool>(),
|
||||||
fields[7].Get<bool>(), fields[8].Get<bool>(), fields[9].Get<bool>(), fields[10].Get<bool>(), fields[11].Get<bool>(), fields[12].Get<uint32>()));
|
fields[7].Get<bool>(), fields[8].Get<bool>(), fields[9].Get<bool>(), fields[10].Get<bool>(), fields[11].Get<bool>(), fields[12].Get<uint32>());
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
@@ -94,7 +94,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
|
|||||||
// Gold at first
|
// Gold at first
|
||||||
if (loot->gold)
|
if (loot->gold)
|
||||||
{
|
{
|
||||||
itemList.push_back(StoredLootItem(0, 0, loot->gold, 0, 0, false, false, false, false, false, false, 0));
|
itemList.emplace_back(0, 0, loot->gold, 0, 0, false, false, false, false, false, false, 0);
|
||||||
|
|
||||||
uint8 index = 0;
|
uint8 index = 0;
|
||||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
|
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
|
||||||
@@ -134,8 +134,8 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
|
|||||||
conditionLootId = li->conditions.front()->SourceGroup;
|
conditionLootId = li->conditions.front()->SourceGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemList.push_back(StoredLootItem(li->itemid, li->itemIndex, li->count, li->randomPropertyId, li->randomSuffix, li->follow_loot_rules, li->freeforall, li->is_blocked, li->is_counted,
|
itemList.emplace_back(li->itemid, li->itemIndex, li->count, li->randomPropertyId, li->randomSuffix, li->follow_loot_rules, li->freeforall, li->is_blocked, li->is_counted,
|
||||||
li->is_underthreshold, li->needs_quest, conditionLootId));
|
li->is_underthreshold, li->needs_quest, conditionLootId);
|
||||||
|
|
||||||
uint8 index = 0;
|
uint8 index = 0;
|
||||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
|
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ void LoadSkillDiscoveryTable()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkillDiscoveryStore[reqSkillOrSpell].push_back(SkillDiscoveryEntry(spellId, reqSkillValue, chance));
|
SkillDiscoveryStore[reqSkillOrSpell].emplace_back(spellId, reqSkillValue, chance);
|
||||||
}
|
}
|
||||||
else if (reqSkillOrSpell == 0) // skill case
|
else if (reqSkillOrSpell == 0) // skill case
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,7 @@ void LoadSkillDiscoveryTable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
|
for (SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
|
||||||
SkillDiscoveryStore[-int32(_spell_idx->second->SkillLine)].push_back(SkillDiscoveryEntry(spellId, reqSkillValue, chance));
|
SkillDiscoveryStore[-int32(_spell_idx->second->SkillLine)].emplace_back(spellId, reqSkillValue, chance);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
questItems.push_back(std::pair(id, count));
|
questItems.emplace_back(id, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!questItems.empty())
|
if (!questItems.empty())
|
||||||
@@ -585,7 +585,7 @@ public:
|
|||||||
for (uint32 const& itemId : quest->RewardChoiceItemId)
|
for (uint32 const& itemId : quest->RewardChoiceItemId)
|
||||||
{
|
{
|
||||||
uint8 index = 0;
|
uint8 index = 0;
|
||||||
questRewardItems.push_back(std::pair(itemId, quest->RewardChoiceItemCount[index++]));
|
questRewardItems.emplace_back(itemId, quest->RewardChoiceItemCount[index++]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ public:
|
|||||||
for (uint32 const& itemId : quest->RewardItemId)
|
for (uint32 const& itemId : quest->RewardItemId)
|
||||||
{
|
{
|
||||||
uint8 index = 0;
|
uint8 index = 0;
|
||||||
questRewardItems.push_back(std::pair(itemId, quest->RewardItemIdCount[index++]));
|
questRewardItems.emplace_back(itemId, quest->RewardItemIdCount[index++]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace MMAP
|
|||||||
mapID = uint32(atoi(file.substr(0, file.size() - 8).c_str()));
|
mapID = uint32(atoi(file.substr(0, file.size() - 8).c_str()));
|
||||||
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
|
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
|
||||||
{
|
{
|
||||||
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
|
m_tiles.emplace_back(mapID, new std::set<uint32>);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ namespace MMAP
|
|||||||
mapID = uint32(atoi(file.substr(0, file.size() - 7).c_str()));
|
mapID = uint32(atoi(file.substr(0, file.size() - 7).c_str()));
|
||||||
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
|
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
|
||||||
{
|
{
|
||||||
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
|
m_tiles.emplace_back(mapID, new std::set<uint32>);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ namespace MMAP
|
|||||||
return (*itr).m_tiles;
|
return (*itr).m_tiles;
|
||||||
|
|
||||||
std::set<uint32>* tiles = new std::set<uint32>();
|
std::set<uint32>* tiles = new std::set<uint32>();
|
||||||
m_tiles.emplace_back(MapTiles(mapID, tiles));
|
m_tiles.emplace_back(mapID, tiles);
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace MMAP
|
|||||||
uint32 m_mapId;
|
uint32 m_mapId;
|
||||||
std::set<uint32>* m_tiles{nullptr};
|
std::set<uint32>* m_tiles{nullptr};
|
||||||
|
|
||||||
bool operator==(uint32 id)
|
bool operator==(uint32 id) const
|
||||||
{
|
{
|
||||||
return m_mapId == id;
|
return m_mapId == id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ namespace MMAP
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
if ((findFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
|
if ((findFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
|
||||||
fileList.push_back(std::string(findFileInfo.cFileName));
|
fileList.emplace_back(findFileInfo.cFileName);
|
||||||
} while (FindNextFile(hFind, &findFileInfo));
|
} while (FindNextFile(hFind, &findFileInfo));
|
||||||
|
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
|
|||||||
Reference in New Issue
Block a user