mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 21:26:23 +00:00
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))
|
||||
{
|
||||
targetSpellStore.push_back(std::make_pair(target, spell));
|
||||
targetSpellStore.emplace_back(target, spell);
|
||||
spellUsed = true;
|
||||
}
|
||||
}
|
||||
@@ -295,7 +295,7 @@ void PetAI::UpdateAI(uint32 diff)
|
||||
|
||||
if (spell->CanAutoCast(ally))
|
||||
{
|
||||
targetSpellStore.push_back(std::make_pair(ally, spell));
|
||||
targetSpellStore.emplace_back(ally, spell);
|
||||
spellUsed = true;
|
||||
break;
|
||||
}
|
||||
@@ -310,7 +310,7 @@ void PetAI::UpdateAI(uint32 diff)
|
||||
{
|
||||
Spell* spell = new Spell(me, spellInfo, TRIGGERED_NONE);
|
||||
if (spell->CanAutoCast(me->GetVictim()))
|
||||
targetSpellStore.push_back(std::make_pair(me->GetVictim(), spell));
|
||||
targetSpellStore.emplace_back(me->GetVictim(), spell);
|
||||
else
|
||||
delete spell;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace AddonMgr
|
||||
std::string name = fields[0].Get<std::string>();
|
||||
uint32 crc = fields[1].Get<uint32>();
|
||||
|
||||
m_knownAddons.push_back(SavedAddon(name, crc));
|
||||
m_knownAddons.emplace_back(name, crc);
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
@@ -76,13 +76,12 @@ namespace AddonMgr
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
BannedAddon addon{};
|
||||
addon.Id = fields[0].Get<uint32>() + offset;
|
||||
addon.Timestamp = uint32(fields[3].Get<uint64>());
|
||||
addon.NameMD5 = Acore::Crypto::MD5::GetDigestOf(fields[1].Get<std::string>());
|
||||
addon.VersionMD5 = Acore::Crypto::MD5::GetDigestOf(fields[2].Get<std::string>());
|
||||
uint32 Id = fields[0].Get<uint32>() + offset;
|
||||
std::array<uint8, 16> NameMD5 = Acore::Crypto::MD5::GetDigestOf(fields[1].Get<std::string>());
|
||||
std::array<uint8, 16> VersionMD5 = Acore::Crypto::MD5::GetDigestOf(fields[2].Get<std::string>());
|
||||
uint32 Timestamp = uint32(fields[3].Get<uint64>());
|
||||
|
||||
m_bannedAddons.emplace_back(addon);
|
||||
m_bannedAddons.emplace_back(Id, NameMD5, VersionMD5, Timestamp);
|
||||
|
||||
++count2;
|
||||
} while (result->NextRow());
|
||||
@@ -94,16 +93,14 @@ namespace AddonMgr
|
||||
|
||||
void SaveAddon(AddonInfo const& addon)
|
||||
{
|
||||
std::string name = addon.Name;
|
||||
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ADDON);
|
||||
|
||||
stmt->SetData(0, name);
|
||||
stmt->SetData(0, addon.Name);
|
||||
stmt->SetData(1, addon.CRC);
|
||||
|
||||
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)
|
||||
|
||||
@@ -38,10 +38,7 @@ struct AddonInfo
|
||||
|
||||
struct SavedAddon
|
||||
{
|
||||
SavedAddon(std::string name, uint32 crc) : Name(std::move(name))
|
||||
{
|
||||
CRC = crc;
|
||||
}
|
||||
SavedAddon(std::string name, uint32 crc) : Name(std::move(name)), CRC(crc) {}
|
||||
|
||||
std::string Name;
|
||||
uint32 CRC;
|
||||
@@ -49,6 +46,9 @@ struct SavedAddon
|
||||
|
||||
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;
|
||||
std::array<uint8, 16> NameMD5;
|
||||
std::array<uint8, 16> VersionMD5;
|
||||
|
||||
@@ -74,7 +74,7 @@ void ChannelMgr::LoadChannels()
|
||||
if (!Utf8toWStr(channelName, channelWName))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void ChannelMgr::LoadChannels()
|
||||
if (!mgr)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ void LootItemStorage::LoadStorageFromDB()
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
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>(),
|
||||
fields[7].Get<bool>(), fields[8].Get<bool>(), fields[9].Get<bool>(), fields[10].Get<bool>(), fields[11].Get<bool>(), fields[12].Get<uint32>()));
|
||||
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>());
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
@@ -94,7 +94,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
|
||||
// Gold at first
|
||||
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;
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
|
||||
@@ -134,8 +134,8 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
|
||||
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,
|
||||
li->is_underthreshold, li->needs_quest, conditionLootId));
|
||||
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);
|
||||
|
||||
uint8 index = 0;
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
|
||||
|
||||
@@ -109,7 +109,7 @@ void LoadSkillDiscoveryTable()
|
||||
continue;
|
||||
}
|
||||
|
||||
SkillDiscoveryStore[reqSkillOrSpell].push_back(SkillDiscoveryEntry(spellId, reqSkillValue, chance));
|
||||
SkillDiscoveryStore[reqSkillOrSpell].emplace_back(spellId, reqSkillValue, chance);
|
||||
}
|
||||
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)
|
||||
SkillDiscoveryStore[-int32(_spell_idx->second->SkillLine)].push_back(SkillDiscoveryEntry(spellId, reqSkillValue, chance));
|
||||
SkillDiscoveryStore[-int32(_spell_idx->second->SkillLine)].emplace_back(spellId, reqSkillValue, chance);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -362,7 +362,7 @@ public:
|
||||
continue;
|
||||
}
|
||||
|
||||
questItems.push_back(std::pair(id, count));
|
||||
questItems.emplace_back(id, count);
|
||||
}
|
||||
|
||||
if (!questItems.empty())
|
||||
@@ -585,7 +585,7 @@ public:
|
||||
for (uint32 const& itemId : quest->RewardChoiceItemId)
|
||||
{
|
||||
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)
|
||||
{
|
||||
uint8 index = 0;
|
||||
questRewardItems.push_back(std::pair(itemId, quest->RewardItemIdCount[index++]));
|
||||
questRewardItems.emplace_back(itemId, quest->RewardItemIdCount[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user