Skip to content

Commit

Permalink
[12747] Fix static analysis repeated expression performance warning (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomGries committed Sep 21, 2014
1 parent bee22a1 commit 40618f8
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 161 deletions.
68 changes: 39 additions & 29 deletions src/game/AuctionHouseBot/AuctionHouseBot.cpp
Expand Up @@ -547,20 +547,21 @@ uint32 AuctionBotBuyer::GetBuyableEntry(AHB_Buyer_Config& config)
ItemPrototype const* prototype = item->GetProto();
if (prototype)
{
++config.SameItemInfo[item->GetEntry()].ItemCount; // Structure constructor will make sure Element are correctly initialised if entry is created here.
config.SameItemInfo[item->GetEntry()].BuyPrice = config.SameItemInfo[item->GetEntry()].BuyPrice + (itr->second->buyout / item->GetCount());
config.SameItemInfo[item->GetEntry()].BidPrice = config.SameItemInfo[item->GetEntry()].BidPrice + (itr->second->startbid / item->GetCount());
if (itr->second->buyout != 0)
BuyerItemInfo& buyerItem = config.SameItemInfo[item->GetEntry()]; // Structure constructor will make sure Element are correctly initialised if entry is created here.
++buyerItem.ItemCount;
buyerItem.BuyPrice = buyerItem.BuyPrice + (Aentry->buyout / item->GetCount());
buyerItem.BidPrice = buyerItem.BidPrice + (Aentry->startbid / item->GetCount());
if (Aentry->buyout != 0)
{
if (itr->second->buyout / item->GetCount() < config.SameItemInfo[item->GetEntry()].MinBuyPrice)
config.SameItemInfo[item->GetEntry()].MinBuyPrice = itr->second->buyout / item->GetCount();
else if (config.SameItemInfo[item->GetEntry()].MinBuyPrice == 0)
config.SameItemInfo[item->GetEntry()].MinBuyPrice = itr->second->buyout / item->GetCount();
if (Aentry->buyout / item->GetCount() < buyerItem.MinBuyPrice)
buyerItem.MinBuyPrice = Aentry->buyout / item->GetCount();
else if (buyerItem.MinBuyPrice == 0)
buyerItem.MinBuyPrice = Aentry->buyout / item->GetCount();
}
if (itr->second->startbid / item->GetCount() < config.SameItemInfo[item->GetEntry()].MinBidPrice)
config.SameItemInfo[item->GetEntry()].MinBidPrice = itr->second->startbid / item->GetCount();
else if (config.SameItemInfo[item->GetEntry()].MinBidPrice == 0)
config.SameItemInfo[item->GetEntry()].MinBidPrice = itr->second->startbid / item->GetCount();
if (Aentry->startbid / item->GetCount() < buyerItem.MinBidPrice)
buyerItem.MinBidPrice = Aentry->startbid / item->GetCount();
else if (buyerItem.MinBidPrice == 0)
buyerItem.MinBidPrice = Aentry->startbid / item->GetCount();

if (!Aentry->owner)
{
Expand Down Expand Up @@ -751,17 +752,18 @@ void AuctionBotBuyer::addNewAuctionBuyerBotBid(AHB_Buyer_Config& config)

for (CheckEntryMap::iterator itr = config.CheckedEntry.begin(); itr != config.CheckedEntry.end();)
{
AuctionEntry* auction = auctionHouse->GetAuction(itr->second.AuctionId);
BuyerAuctionEval& auctionEval = itr->second;
AuctionEntry* auction = auctionHouse->GetAuction(auctionEval.AuctionId);
if (!auction || auction->moneyDeliveryTime) // is auction not active now
{
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: Entry %u on ah %u doesn't exists, perhaps bought already?",
itr->second.AuctionId, auction->GetHouseId());
auctionEval.AuctionId, auction->GetHouseId());

config.CheckedEntry.erase(itr++);
continue;
}

if ((itr->second.LastChecked != 0) && ((Now - itr->second.LastChecked) <= m_CheckInterval))
if ((auctionEval.LastChecked != 0) && ((Now - auctionEval.LastChecked) <= m_CheckInterval))
{
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: In time interval wait for entry %u!", auction->Id);
++itr;
Expand All @@ -786,13 +788,10 @@ void AuctionBotBuyer::addNewAuctionBuyerBotBid(AHB_Buyer_Config& config)
BasePrice *= item->GetCount();

double MaxBuyablePrice = (BasePrice * config.BuyerPriceRatio) / 100;
BuyerItemInfoMap::iterator sameitem_itr = config.SameItemInfo.find(item->GetEntry());
uint32 buyoutPrice = auction->buyout / item->GetCount();

uint32 bidPrice;
uint32 bidPriceByItem;
uint32 minBidPrice;
uint32 minBuyPrice;

if (auction->bid >= auction->startbid)
{
bidPrice = auction->GetAuctionOutBid();
Expand All @@ -806,6 +805,10 @@ void AuctionBotBuyer::addNewAuctionBuyerBotBid(AHB_Buyer_Config& config)

double InGame_BuyPrice;
double InGame_BidPrice;
uint32 minBidPrice;
uint32 minBuyPrice;

BuyerItemInfoMap::iterator sameitem_itr = config.SameItemInfo.find(item->GetEntry());
if (sameitem_itr == config.SameItemInfo.end())
{
InGame_BuyPrice = 0;
Expand All @@ -815,17 +818,21 @@ void AuctionBotBuyer::addNewAuctionBuyerBotBid(AHB_Buyer_Config& config)
}
else
{
if (sameitem_itr->second.ItemCount == 1) MaxBuyablePrice = MaxBuyablePrice * 5; // if only one item exist can be buyed if the price is high too.
InGame_BuyPrice = sameitem_itr->second.BuyPrice / sameitem_itr->second.ItemCount;
InGame_BidPrice = sameitem_itr->second.BidPrice / sameitem_itr->second.ItemCount;
minBidPrice = sameitem_itr->second.MinBidPrice;
minBuyPrice = sameitem_itr->second.MinBuyPrice;
const BuyerItemInfo& sameBuyerItem = sameitem_itr->second;

if (sameBuyerItem.ItemCount == 1)
MaxBuyablePrice = MaxBuyablePrice * 5; // if only one item exist can be bought if the price is high too.

InGame_BuyPrice = sameBuyerItem.BuyPrice / sameBuyerItem.ItemCount;
InGame_BidPrice = sameBuyerItem.BidPrice / sameBuyerItem.ItemCount;
minBidPrice = sameBuyerItem.MinBidPrice;
minBuyPrice = sameBuyerItem.MinBuyPrice;
}

double MaxBidablePrice = MaxBuyablePrice - (MaxBuyablePrice / 30); // Max Bidable price defined to 70% of max buyable price

DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: Auction added with data:");
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: MaxPrice of Entry %u is %.1fg.", itr->second.AuctionId, MaxBuyablePrice / 10000);
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: MaxPrice of Entry %u is %.1fg.", auctionEval.AuctionId, MaxBuyablePrice / 10000);
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: GamePrice buy=%.1fg, bid=%.1fg.", InGame_BuyPrice / 10000, InGame_BidPrice / 10000);
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: Minimal price see in AH Buy=%ug, Bid=%ug.",
minBuyPrice / 10000, minBidPrice / 10000);
Expand Down Expand Up @@ -854,7 +861,7 @@ void AuctionBotBuyer::addNewAuctionBuyerBotBid(AHB_Buyer_Config& config)
if (IsBidableEntry(bidPriceByItem, InGame_BuyPrice, MaxBidablePrice, minBidPrice, MaxChance, config.FactionChance))
PlaceBidToEntry(auction, bidPrice);

itr->second.LastChecked = Now;
auctionEval.LastChecked = Now;
--BuyCycles;

++itr;
Expand Down Expand Up @@ -1766,9 +1773,12 @@ void AuctionHouseBot::Rebuild(bool all)
{
AuctionHouseObject::AuctionEntryMapBounds bounds = sAuctionMgr.GetAuctionsMap(AuctionHouseType(i))->GetAuctionsBounds();
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
if (!itr->second->owner) // ahbot auction
if (all || itr->second->bid == 0) // expire now auction if no bid or forced
itr->second->expireTime = sWorld.GetGameTime();
{
AuctionEntry* entry = itr->second;
if (!entry->owner) // ahbot auction
if (all || entry->bid == 0) // expire now auction if no bid or forced
entry->expireTime = sWorld.GetGameTime();
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/game/BattleGround/BattleGround.cpp
Expand Up @@ -1268,11 +1268,12 @@ void BattleGround::RemoveFromBGFreeSlotQueue()
{
// set to be able to re-add if needed
m_InBGFreeSlotQueue = false;
for (BGFreeSlotQueueType::iterator itr = sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].begin(); itr != sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].end(); ++itr)
BGFreeSlotQueueType& bgFreeSlot = sBattleGroundMgr.BGFreeSlotQueue[m_TypeID];
for (BGFreeSlotQueueType::iterator itr = bgFreeSlot.begin(); itr != bgFreeSlot.end(); ++itr)
{
if ((*itr)->GetInstanceID() == GetInstanceID())
{
sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].erase(itr);
bgFreeSlot.erase(itr);
return;
}
}
Expand Down
34 changes: 18 additions & 16 deletions src/game/BattleGround/BattleGroundMgr.cpp
Expand Up @@ -1306,13 +1306,15 @@ void BattleGroundMgr::BuildPvpLogDataPacket(WorldPacket* data, BattleGround* bg)

for (BattleGround::BattleGroundScoreMap::const_iterator itr = bg->GetPlayerScoresBegin(); itr != bg->GetPlayerScoresEnd(); ++itr)
{
const BattleGroundScore* score = itr->second;

*data << ObjectGuid(itr->first);
*data << (int32)itr->second->KillingBlows;
*data << (int32)score->KillingBlows;
if (type == 0)
{
*data << (int32)itr->second->HonorableKills;
*data << (int32)itr->second->Deaths;
*data << (int32)(itr->second->BonusHonor);
*data << (int32)score->HonorableKills;
*data << (int32)score->Deaths;
*data << (int32)(score->BonusHonor);
}
else
{
Expand All @@ -1326,31 +1328,31 @@ void BattleGroundMgr::BuildPvpLogDataPacket(WorldPacket* data, BattleGround* bg)
else
*data << uint8(0);
}
*data << (int32)itr->second->DamageDone; // damage done
*data << (int32)itr->second->HealingDone; // healing done
*data << (int32)score->DamageDone; // damage done
*data << (int32)score->HealingDone; // healing done
switch (bg->GetTypeID()) // battleground specific things
{
case BATTLEGROUND_AV:
*data << (uint32)0x00000005; // count of next fields
*data << (uint32)((BattleGroundAVScore*)itr->second)->GraveyardsAssaulted; // GraveyardsAssaulted
*data << (uint32)((BattleGroundAVScore*)itr->second)->GraveyardsDefended; // GraveyardsDefended
*data << (uint32)((BattleGroundAVScore*)itr->second)->TowersAssaulted; // TowersAssaulted
*data << (uint32)((BattleGroundAVScore*)itr->second)->TowersDefended; // TowersDefended
*data << (uint32)((BattleGroundAVScore*)itr->second)->SecondaryObjectives; // SecondaryObjectives - free some of the Lieutnants
*data << (uint32)((BattleGroundAVScore*)score)->GraveyardsAssaulted; // GraveyardsAssaulted
*data << (uint32)((BattleGroundAVScore*)score)->GraveyardsDefended; // GraveyardsDefended
*data << (uint32)((BattleGroundAVScore*)score)->TowersAssaulted; // TowersAssaulted
*data << (uint32)((BattleGroundAVScore*)score)->TowersDefended; // TowersDefended
*data << (uint32)((BattleGroundAVScore*)score)->SecondaryObjectives; // SecondaryObjectives - free some of the Lieutnants
break;
case BATTLEGROUND_WS:
*data << (uint32)0x00000002; // count of next fields
*data << (uint32)((BattleGroundWGScore*)itr->second)->FlagCaptures; // flag captures
*data << (uint32)((BattleGroundWGScore*)itr->second)->FlagReturns; // flag returns
*data << (uint32)((BattleGroundWGScore*)score)->FlagCaptures; // flag captures
*data << (uint32)((BattleGroundWGScore*)score)->FlagReturns; // flag returns
break;
case BATTLEGROUND_AB:
*data << (uint32)0x00000002; // count of next fields
*data << (uint32)((BattleGroundABScore*)itr->second)->BasesAssaulted; // bases asssulted
*data << (uint32)((BattleGroundABScore*)itr->second)->BasesDefended; // bases defended
*data << (uint32)((BattleGroundABScore*)score)->BasesAssaulted; // bases asssulted
*data << (uint32)((BattleGroundABScore*)score)->BasesDefended; // bases defended
break;
case BATTLEGROUND_EY:
*data << (uint32)0x00000001; // count of next fields
*data << (uint32)((BattleGroundEYScore*)itr->second)->FlagCaptures; // flag captures
*data << (uint32)((BattleGroundEYScore*)score)->FlagCaptures; // flag captures
break;
case BATTLEGROUND_NA:
case BATTLEGROUND_BE:
Expand Down
9 changes: 5 additions & 4 deletions src/game/Calendar.cpp
Expand Up @@ -491,18 +491,19 @@ void CalendarMgr::CopyEvent(uint64 eventId, time_t newTime, ObjectGuid const& gu

while (ci_itr != cInvMap->end())
{
if (ci_itr->second->InviteeGuid == guid)
const CalendarInvite* invite = ci_itr->second;
if (invite->InviteeGuid == guid)
{
AddInvite(newEvent, guid, ci_itr->second->InviteeGuid, CALENDAR_STATUS_CONFIRMED, CALENDAR_RANK_OWNER, "", time(NULL));
AddInvite(newEvent, guid, invite->InviteeGuid, CALENDAR_STATUS_CONFIRMED, CALENDAR_RANK_OWNER, "", time(NULL));
}
else
{
CalendarModerationRank rank = CALENDAR_RANK_PLAYER;
// copy moderator rank
if (ci_itr->second->Rank == CALENDAR_RANK_MODERATOR)
if (invite->Rank == CALENDAR_RANK_MODERATOR)
rank = CALENDAR_RANK_MODERATOR;

AddInvite(newEvent, guid, ci_itr->second->InviteeGuid, CALENDAR_STATUS_INVITED, rank, "", time(NULL));
AddInvite(newEvent, guid, invite->InviteeGuid, CALENDAR_STATUS_INVITED, rank, "", time(NULL));
}
++ci_itr;
}
Expand Down
14 changes: 10 additions & 4 deletions src/game/Creature.cpp
Expand Up @@ -691,13 +691,19 @@ void Creature::RegeneratePower()
// Apply modifiers (if any)
AuraList const& ModPowerRegenAuras = GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
for (AuraList::const_iterator i = ModPowerRegenAuras.begin(); i != ModPowerRegenAuras.end(); ++i)
if ((*i)->GetModifier()->m_miscvalue == int32(powerType))
addValue += (*i)->GetModifier()->m_amount;
{
Modifier const* modifier = (*i)->GetModifier();
if (modifier->m_miscvalue == int32(powerType))
addValue += modifier->m_amount;
}

AuraList const& ModPowerRegenPCTAuras = GetAurasByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT);
for (AuraList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i)
if ((*i)->GetModifier()->m_miscvalue == int32(powerType))
addValue *= ((*i)->GetModifier()->m_amount + 100) / 100.0f;
{
Modifier const* modifier = (*i)->GetModifier();
if (modifier->m_miscvalue == int32(powerType))
addValue *= (modifier->m_amount + 100) / 100.0f;
}

ModifyPower(powerType, int32(addValue));
}
Expand Down
7 changes: 4 additions & 3 deletions src/game/CreatureAI.cpp
Expand Up @@ -148,12 +148,13 @@ void CreatureAI::SetCombatMovement(bool enable, bool stopOrStartMovement /*=fals

void CreatureAI::HandleMovementOnAttackStart(Unit* victim)
{
MotionMaster* creatureMotion = m_creature->GetMotionMaster();
if (m_isCombatMovement)
m_creature->GetMotionMaster()->MoveChase(victim, m_attackDistance, m_attackAngle);
creatureMotion->MoveChase(victim, m_attackDistance, m_attackAngle);
// TODO - adapt this to only stop OOC-MMGens when MotionMaster rewrite is finished
else if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE || m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == RANDOM_MOTION_TYPE)
else if (creatureMotion->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE || creatureMotion->GetCurrentMovementGeneratorType() == RANDOM_MOTION_TYPE)
{
m_creature->GetMotionMaster()->MoveIdle();
creatureMotion->MoveIdle();
m_creature->StopMoving();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/game/CreatureEventAI.cpp
Expand Up @@ -94,7 +94,9 @@ CreatureEventAI::CreatureEventAI(Creature* c) : CreatureAI(c),
if (creatureEventsItr != sEventAIMgr.GetCreatureEventAIMap().end())
{
uint32 events_count = 0;
for (CreatureEventAI_Event_Vec::const_iterator i = creatureEventsItr->second.begin(); i != creatureEventsItr->second.end(); ++i)

const CreatureEventAI_Event_Vec &creatureEvent = creatureEventsItr->second;
for (CreatureEventAI_Event_Vec::const_iterator i = creatureEvent.begin(); i != creatureEvent.end(); ++i)
{
// Debug check
#ifndef MANGOS_DEBUG
Expand All @@ -117,7 +119,7 @@ CreatureEventAI::CreatureEventAI(Creature* c) : CreatureAI(c),
else
{
m_CreatureEventAIList.reserve(events_count);
for (CreatureEventAI_Event_Vec::const_iterator i = creatureEventsItr->second.begin(); i != creatureEventsItr->second.end(); ++i)
for (CreatureEventAI_Event_Vec::const_iterator i = creatureEvent.begin(); i != creatureEvent.end(); ++i)
{
// Debug check
#ifndef MANGOS_DEBUG
Expand Down
14 changes: 9 additions & 5 deletions src/game/GridNotifiers.h
Expand Up @@ -512,8 +512,11 @@ namespace MaNGOS
void Visit(CameraMapType& m)
{
for (CameraMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
if (itr->getSource()->GetBody()->InSamePhase(i_searcher) && itr->getSource()->GetBody()->IsWithinDist(i_searcher, i_dist))
i_do(itr->getSource()->GetOwner());
{
Camera* camera = itr->getSource();
if (camera->GetBody()->InSamePhase(i_searcher) && camera->GetBody()->IsWithinDist(i_searcher, i_dist))
i_do(camera->GetOwner());
}
}
template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
};
Expand Down Expand Up @@ -635,13 +638,14 @@ namespace MaNGOS
WorldObject const& GetFocusObject() const { return *i_unit; }
bool operator()(GameObject* go) const
{
if (go->GetGOInfo()->type != GAMEOBJECT_TYPE_SPELL_FOCUS)
GameObjectInfo const* goInfo = go->GetGOInfo();
if (goInfo->type != GAMEOBJECT_TYPE_SPELL_FOCUS)
return false;

if (go->GetGOInfo()->spellFocus.focusId != i_focusId)
if (goInfo->spellFocus.focusId != i_focusId)
return false;

float dist = (float)go->GetGOInfo()->spellFocus.dist;
float dist = (float)goInfo->spellFocus.dist;

return go->IsWithinDistInMap(i_unit, dist);
}
Expand Down

0 comments on commit 40618f8

Please sign in to comment.