refactor(Core): apply clang-tidy modernize-loop-convert (#3822)

This commit is contained in:
Francesco Borzì
2020-12-07 19:04:19 +01:00
committed by GitHub
parent 0b7b36f20c
commit 0b8ec1f6ee
16 changed files with 125 additions and 130 deletions

View File

@@ -90,8 +90,8 @@ public:
AuctionHouseObject() { next = AuctionsMap.begin(); }
~AuctionHouseObject()
{
for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
delete itr->second;
for (auto & itr : AuctionsMap)
delete itr.second;
}
typedef std::map<uint32, AuctionEntry*> AuctionEntryMap;

View File

@@ -229,10 +229,8 @@ public:
if (threatList.empty())
return;
for (ThreatContainer::StorageType::iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
for (auto ref : threatList)
{
HostileReference* ref = (*itr);
if (predicate(ref->getTarget()))
{
ref->setThreat(0);

View File

@@ -390,8 +390,8 @@ struct TrainerSpell
{
TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0)
{
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
learnedSpell[i] = 0;
for (unsigned int & i : learnedSpell)
i = 0;
}
uint32 spell;

View File

@@ -844,8 +844,8 @@ public:
void AddToSkillupList(uint32 PlayerGuidLow) { m_SkillupList.push_back(PlayerGuidLow); }
[[nodiscard]] bool IsInSkillupList(uint32 PlayerGuidLow) const
{
for (std::list<uint32>::const_iterator i = m_SkillupList.begin(); i != m_SkillupList.end(); ++i)
if (*i == PlayerGuidLow)
for (unsigned int i : m_SkillupList)
if (i == PlayerGuidLow)
return true;
return false;

View File

@@ -264,7 +264,7 @@ struct PlayerClassInfo
struct PlayerLevelInfo
{
PlayerLevelInfo() { for (uint8 i = 0; i < MAX_STATS; ++i) stats[i] = 0; }
PlayerLevelInfo() { for (unsigned char & stat : stats) stat = 0; }
uint8 stats[MAX_STATS];
};
@@ -689,8 +689,8 @@ struct EquipmentSet
{
EquipmentSet() : Guid(0), IgnoreMask(0), state(EQUIPMENT_SET_NEW)
{
for (uint8 i = 0; i < EQUIPMENT_SLOT_END; ++i)
Items[i] = 0;
for (unsigned int & Item : Items)
Item = 0;
}
uint64 Guid;
@@ -1876,8 +1876,8 @@ public:
{
Unit::SetPvP(state);
if (!m_Controlled.empty())
for (ControlSet::iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr)
(*itr)->SetPvP(state);
for (auto itr : m_Controlled)
itr->SetPvP(state);
}
void UpdatePvP(bool state, bool _override = false);
void UpdateZone(uint32 newZone, uint32 newArea);
@@ -2272,8 +2272,8 @@ public:
[[nodiscard]] bool InBattlegroundQueue() const
{
for (uint8 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i)
if (m_bgBattlegroundQueueID[i] != BATTLEGROUND_QUEUE_NONE)
for (auto i : m_bgBattlegroundQueueID)
if (i != BATTLEGROUND_QUEUE_NONE)
return true;
return false;
}
@@ -2308,18 +2308,18 @@ public:
bool HasFreeBattlegroundQueueId()
{
for (uint8 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i)
if (m_bgBattlegroundQueueID[i] == BATTLEGROUND_QUEUE_NONE)
for (auto & i : m_bgBattlegroundQueueID)
if (i == BATTLEGROUND_QUEUE_NONE)
return true;
return false;
}
void RemoveBattlegroundQueueId(BattlegroundQueueTypeId val)
{
for (uint8 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i)
if (m_bgBattlegroundQueueID[i] == val)
for (auto & i : m_bgBattlegroundQueueID)
if (i == val)
{
m_bgBattlegroundQueueID[i] = BATTLEGROUND_QUEUE_NONE;
i = BATTLEGROUND_QUEUE_NONE;
return;
}
}
@@ -3031,10 +3031,8 @@ template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T& bas
if (m_spellModTakingSpell)
spell = m_spellModTakingSpell;
for (SpellModList::iterator itr = m_spellMods[op].begin(); itr != m_spellMods[op].end(); ++itr)
for (auto mod : m_spellMods[op])
{
SpellModifier* mod = *itr;
// Charges can be set only for mods with auras
if (!mod->ownerAura)
ASSERT(mod->charges == 0);

View File

@@ -511,7 +511,7 @@ typedef std::pair<QuestRelations::const_iterator, QuestRelations::const_iterator
struct PetLevelInfo
{
PetLevelInfo() : health(0), mana(0), armor(0), min_dmg(0), max_dmg(0) { for (uint8 i = 0; i < MAX_STATS; ++i) stats[i] = 0; }
PetLevelInfo() : health(0), mana(0), armor(0), min_dmg(0), max_dmg(0) { for (unsigned short & stat : stats) stat = 0; }
uint16 stats[MAX_STATS];
uint16 health;
@@ -1076,9 +1076,9 @@ public:
if (map_itr == _mailLevelRewardStore.end())
return nullptr;
for (MailLevelRewardList::const_iterator set_itr = map_itr->second.begin(); set_itr != map_itr->second.end(); ++set_itr)
if (set_itr->raceMask & raceMask)
return &*set_itr;
for (const auto & set_itr : map_itr->second)
if (set_itr.raceMask & raceMask)
return &set_itr;
return nullptr;
}

View File

@@ -906,11 +906,11 @@ struct FactionTemplateEntry
if (entry.faction)
{
for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i)
if (enemyFaction[i] == entry.faction)
for (unsigned int i : enemyFaction)
if (i == entry.faction)
return false;
for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i)
if (friendFaction[i] == entry.faction)
for (unsigned int i : friendFaction)
if (i == entry.faction)
return true;
}
return (friendlyMask & entry.ourMask) || (ourMask & entry.friendlyMask);
@@ -919,11 +919,11 @@ struct FactionTemplateEntry
{
if (entry.faction)
{
for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i)
if (enemyFaction[i] == entry.faction)
for (unsigned int i : enemyFaction)
if (i == entry.faction)
return true;
for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i)
if (friendFaction[i] == entry.faction)
for (unsigned int i : friendFaction)
if (i == entry.faction)
return false;
}
return (hostileMask & entry.ourMask) != 0;
@@ -931,8 +931,8 @@ struct FactionTemplateEntry
[[nodiscard]] bool IsHostileToPlayers() const { return (hostileMask & FACTION_MASK_PLAYER) != 0; }
[[nodiscard]] bool IsNeutralToAll() const
{
for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i)
if (enemyFaction[i] != 0)
for (unsigned int i : enemyFaction)
if (i != 0)
return false;
return hostileMask == 0 && friendlyMask == 0;
}