Skip to content

Commit

Permalink
Fix postfixOperator (#11097)
Browse files Browse the repository at this point in the history
Id: postfixOperator
CWE: 398
Prefix ++/-- operators should be preferred for non-primitive types. Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code.
  • Loading branch information
JohnsterID authored Jul 8, 2024
1 parent 847bda3 commit 9ad006c
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 103 deletions.
8 changes: 4 additions & 4 deletions CvGameCoreDLL_Expansion2/CvBarbarians.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ void CvBarbarians::DoCamps()
int iY = pLoopPlot->getY();
bool bTooClose = false;

for (std::vector<int>::iterator it = MajorCapitals.begin(); it != MajorCapitals.end(); it++)
for (std::vector<int>::iterator it = MajorCapitals.begin(); it != MajorCapitals.end(); ++it)
{
CvPlot* pInvalidAreaPlot = theMap.plotByIndex(*it);
int iDistance = plotDistance(iX, iY, pInvalidAreaPlot->getX(), pInvalidAreaPlot->getY());
Expand All @@ -825,7 +825,7 @@ void CvBarbarians::DoCamps()
}
if (!bTooClose)
{
for (std::vector<int>::iterator it = BarbCamps.begin(); it != BarbCamps.end(); it++)
for (std::vector<int>::iterator it = BarbCamps.begin(); it != BarbCamps.end(); ++it)
{
CvPlot* pInvalidAreaPlot = theMap.plotByIndex(*it);
int iDistance = plotDistance(iX, iY, pInvalidAreaPlot->getX(), pInvalidAreaPlot->getY());
Expand All @@ -838,7 +838,7 @@ void CvBarbarians::DoCamps()
}
if (!bTooClose)
{
for (std::vector<int>::iterator it = RecentlyClearedBarbCamps.begin(); it != RecentlyClearedBarbCamps.end(); it++)
for (std::vector<int>::iterator it = RecentlyClearedBarbCamps.begin(); it != RecentlyClearedBarbCamps.end(); ++it)
{
CvPlot* pInvalidAreaPlot = theMap.plotByIndex(*it);
int iDistance = plotDistance(iX, iY, pInvalidAreaPlot->getX(), pInvalidAreaPlot->getY());
Expand Down Expand Up @@ -928,7 +928,7 @@ void CvBarbarians::DoCamps()
ActivateBarbSpawner(pPlot);

// Show the new camp to any who have the policy
for (std::vector<PlayerTypes>::iterator it = vThoseWhoSee.begin(); it != vThoseWhoSee.end(); it++)
for (std::vector<PlayerTypes>::iterator it = vThoseWhoSee.begin(); it != vThoseWhoSee.end(); ++it)
{
TeamTypes eTeam = GET_PLAYER(*it).getTeam();
if (pPlot->isRevealed(eTeam))
Expand Down
4 changes: 2 additions & 2 deletions CvGameCoreDLL_Expansion2/CvCity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20524,7 +20524,7 @@ void CvCity::UpdateEventGPPFromSpecialistsCounters()
}
else
{
it++;
++it;
}
}
}
Expand Down Expand Up @@ -32141,7 +32141,7 @@ bool CvCity::IsInDangerFromPlayers(vector<PlayerTypes>& vWarAllies) const
CvWeightedVector<PlayerTypes> veEnemyOtherPowers;
std::map<PlayerTypes, int> vectorIndices;
int iIndex = 0;
for (std::vector<PlayerTypes>::iterator it = vWarAllies.begin(); it != vWarAllies.end(); it++)
for (std::vector<PlayerTypes>::iterator it = vWarAllies.begin(); it != vWarAllies.end(); ++it)
{
veEnemyLandPowers.push_back(*it, 0);
veEnemySeaPowers.push_back(*it, 0);
Expand Down
14 changes: 7 additions & 7 deletions CvGameCoreDLL_Expansion2/CvContractClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ void CvGameContracts::DoUpdateContracts()

//This is expensive, so do it sparingly!
ContractList::iterator it;
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); it++)
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); ++it)
{
CvContract kContract = (*it);
for(int iI = 0; iI < GC.getNumUnitInfos(); iI++)
Expand Down Expand Up @@ -722,7 +722,7 @@ CvContract* CvGameContracts::GetActiveContract(ContractTypes eContract)
return NULL;

ContractList::iterator it;
for(it = m_ActiveContracts.begin(); it != m_ActiveContracts.end(); it++)
for(it = m_ActiveContracts.begin(); it != m_ActiveContracts.end(); ++it)
{
if(it->m_eContract == eContract)
{
Expand All @@ -738,7 +738,7 @@ CvContract* CvGameContracts::GetInactiveContract(ContractTypes eContract)
return NULL;

ContractList::iterator it;
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); it++)
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); ++it)
{
if(it->m_eContract == eContract)
{
Expand Down Expand Up @@ -772,7 +772,7 @@ bool CvGameContracts::IsContractActive(ContractTypes eContract)
return false;

ContractList::iterator it;
for(it = m_ActiveContracts.begin(); it != m_ActiveContracts.end(); it++)
for(it = m_ActiveContracts.begin(); it != m_ActiveContracts.end(); ++it)
{
CvContract kContract = (*it);
if(kContract.m_eContract == eContract)
Expand All @@ -788,7 +788,7 @@ bool CvGameContracts::IsContractAvailable(ContractTypes eContract)
return false;

ContractList::iterator it;
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); it++)
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); ++it)
{
CvContract kContract = (*it);
if(kContract.m_eContract == eContract)
Expand All @@ -807,7 +807,7 @@ void CvGameContracts::StartContract(CvContract kContract)

//And remove it from the inactive list.
ContractList::iterator it;
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); it++)
for(it = m_InactiveContracts.begin(); it != m_InactiveContracts.end(); ++it)
{
CvContract kInactiveContract = (*it);
if(kContract.m_eContract == kInactiveContract.m_eContract)
Expand All @@ -821,7 +821,7 @@ void CvGameContracts::StartContract(CvContract kContract)
void CvGameContracts::EndContract(ContractTypes eContract, PlayerTypes ePlayer)
{
ContractList::iterator it;
for(it = m_ActiveContracts.begin(); it != m_ActiveContracts.end(); it++)
for(it = m_ActiveContracts.begin(); it != m_ActiveContracts.end(); ++it)
{
CvContract kContract = (*it);
if(kContract.m_eContract == eContract && kContract.m_eContractHolder == ePlayer)
Expand Down
8 changes: 4 additions & 4 deletions CvGameCoreDLL_Expansion2/CvCorporationClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ void CvGameCorporations::DoTurn()
CvCorporation* CvGameCorporations::GetCorporation(CorporationTypes eCorporation)
{
CorporationList::iterator it;
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); it++)
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); ++it)
{
if(it->m_eCorporation == eCorporation)
{
Expand Down Expand Up @@ -1772,7 +1772,7 @@ void CvGameCorporations::DestroyCorporation(CorporationTypes eCorporation)
return;

CorporationList::iterator it;
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); it++)
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); ++it)
{
CvCorporation kCorporation = (*it);
if(kCorporation.m_eCorporation == eCorporation)
Expand Down Expand Up @@ -1930,7 +1930,7 @@ bool CvGameCorporations::CanFoundCorporation(PlayerTypes ePlayer, CorporationTyp
bool CvGameCorporations::IsCorporationFounded(CorporationTypes eCorporation) const
{
CorporationList::const_iterator it;
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); it++)
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); ++it)
{
if((*it).m_eCorporation == eCorporation)
return true;
Expand All @@ -1946,7 +1946,7 @@ bool CvGameCorporations::IsCorporationHeadquarters(CvCity* pCity) const
return false;

CorporationList::const_iterator it;
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); it++)
for(it = m_ActiveCorporations.begin(); it != m_ActiveCorporations.end(); ++it)
{
if((*it).m_iHeadquartersCityX == pCity->getX() &&
(*it).m_iHeadquartersCityY == pCity->getY())
Expand Down
42 changes: 21 additions & 21 deletions CvGameCoreDLL_Expansion2/CvCultureClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ PlayerTypes CvGameCulture::GetGreatWorkController(int iIndex) const
bool CvGameCulture::IsGreatWorkCreated(GreatWorkType eType) const
{
GreatWorkList::const_iterator it;
for(it = m_CurrentGreatWorks.begin(); it != m_CurrentGreatWorks.end(); it++)
for(it = m_CurrentGreatWorks.begin(); it != m_CurrentGreatWorks.end(); ++it)
{
if ((*it).m_eType == eType)
{
Expand Down Expand Up @@ -1369,7 +1369,7 @@ void CvPlayerCulture::MoveWorks(GreatWorkSlotType eType, vector<CvGreatWorkBuild
// First building that are not endangered and not puppets
// CUSTOMLOG(" ... theming safe buildings");
vector<CvGreatWorkBuildingInMyEmpire>::iterator itBuilding;
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); ++itBuilding)
{
if (!itBuilding->m_bEndangered && !itBuilding->m_bPuppet)
{
Expand All @@ -1384,7 +1384,7 @@ void CvPlayerCulture::MoveWorks(GreatWorkSlotType eType, vector<CvGreatWorkBuild

// Next building that are not endangered and are puppets
// CUSTOMLOG(" ... theming safe buildings");
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); ++itBuilding)
{
if (!itBuilding->m_bEndangered && itBuilding->m_bPuppet)
{
Expand Down Expand Up @@ -1484,7 +1484,7 @@ void CvPlayerCulture::MoveWorks(GreatWorkSlotType eType, vector<CvGreatWorkBuild
if (eType != CvTypes::getGREAT_WORK_SLOT_MUSIC())
{
// CUSTOMLOG(" ... checking safe buildings for swaps");
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); ++itBuilding)
{
if (!itBuilding->m_bEndangered && !itBuilding->m_bThemed)
{
Expand All @@ -1500,7 +1500,7 @@ void CvPlayerCulture::MoveWorks(GreatWorkSlotType eType, vector<CvGreatWorkBuild

// Then endangered ones
// CUSTOMLOG(" ... theming endangered buildings");
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); ++itBuilding)
{
if (itBuilding->m_bEndangered)
{
Expand All @@ -1518,7 +1518,7 @@ void CvPlayerCulture::MoveWorks(GreatWorkSlotType eType, vector<CvGreatWorkBuild
if(bSecondUpdate || bUpdate)
{
std::vector<CvCity*> CityList;
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); ++itBuilding)
{
CvCity* pCity = m_pPlayer->getCity(itBuilding->m_iCityID);
if (pCity != NULL)
Expand Down Expand Up @@ -1603,7 +1603,7 @@ bool CvPlayerCulture::ThemeBuilding(vector<CvGreatWorkBuildingInMyEmpire>::const
else
{
worksToConsider = works1;
for (it = works2.begin(); it != works2.end(); it++)
for (it = works2.begin(); it != works2.end(); ++it)
{
worksToConsider.push_back(*it);
}
Expand All @@ -1617,7 +1617,7 @@ bool CvPlayerCulture::ThemeBuilding(vector<CvGreatWorkBuildingInMyEmpire>::const
}

// Try each of the works as the starter
for (it = worksToConsider.begin(); it != worksToConsider.end(); it++)
for (it = worksToConsider.begin(); it != worksToConsider.end(); ++it)
{
// First, make sure this "starter" is valid
if (pkBonusInfo->IsRequiresOwner() && it->m_ePlayer != m_pPlayer->GetID())
Expand Down Expand Up @@ -2067,7 +2067,7 @@ bool CvPlayerCulture::ThemeEqualArtArtifact(CvGreatWorkBuildingInMyEmpire kBldg,
int iCountSlots = pkEntry->GetGreatWorkCount();

// Try each of the Artifacts as the starter
for (it = works2.begin(); it != works2.end(); it++)
for (it = works2.begin(); it != works2.end(); ++it)
{
// First, make sure this "starter" is valid
if (pkBonusInfo->IsRequiresOwner() && it->m_ePlayer != m_pPlayer->GetID())
Expand Down Expand Up @@ -2574,7 +2574,7 @@ bool CvPlayerCulture::MoveSingleWorks(vector<CvGreatWorkBuildingInMyEmpire> &bui
vector<CvGreatWorkBuildingInMyEmpire> endangeredBuildingsAny;
vector<CvGreatWorkBuildingInMyEmpire> endangeredBuildingsNone;

for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)
for (itBuilding = buildings.begin(); itBuilding != buildings.end(); ++itBuilding)
{
if (!itBuilding->m_bThemed) {
if (!itBuilding->m_bEndangered) {
Expand Down Expand Up @@ -2613,31 +2613,31 @@ bool CvPlayerCulture::MoveSingleWorks(vector<CvGreatWorkBuildingInMyEmpire> &bui
}
bool bUpdate = false;

for (itBuilding = homelandBuildingsFocus.begin(); itBuilding != homelandBuildingsFocus.end(); itBuilding++) {
for (itBuilding = homelandBuildingsFocus.begin(); itBuilding != homelandBuildingsFocus.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = homelandBuildingsAny.begin(); itBuilding != homelandBuildingsAny.end(); itBuilding++) {
for (itBuilding = homelandBuildingsAny.begin(); itBuilding != homelandBuildingsAny.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = homelandBuildingsNone.begin(); itBuilding != homelandBuildingsNone.end(); itBuilding++) {
for (itBuilding = homelandBuildingsNone.begin(); itBuilding != homelandBuildingsNone.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = puppetBuildingsFocus.begin(); itBuilding != puppetBuildingsFocus.end(); itBuilding++) {
for (itBuilding = puppetBuildingsFocus.begin(); itBuilding != puppetBuildingsFocus.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = puppetBuildingsAny.begin(); itBuilding != puppetBuildingsAny.end(); itBuilding++) {
for (itBuilding = puppetBuildingsAny.begin(); itBuilding != puppetBuildingsAny.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = puppetBuildingsNone.begin(); itBuilding != puppetBuildingsNone.end(); itBuilding++) {
for (itBuilding = puppetBuildingsNone.begin(); itBuilding != puppetBuildingsNone.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = endangeredBuildingsFocus.begin(); itBuilding != endangeredBuildingsFocus.end(); itBuilding++) {
for (itBuilding = endangeredBuildingsFocus.begin(); itBuilding != endangeredBuildingsFocus.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = endangeredBuildingsAny.begin(); itBuilding != endangeredBuildingsAny.end(); itBuilding++) {
for (itBuilding = endangeredBuildingsAny.begin(); itBuilding != endangeredBuildingsAny.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
for (itBuilding = endangeredBuildingsNone.begin(); itBuilding != endangeredBuildingsNone.end(); itBuilding++) {
for (itBuilding = endangeredBuildingsNone.begin(); itBuilding != endangeredBuildingsNone.end(); ++itBuilding) {
bUpdate = FillBuilding(itBuilding, works1, works2);
}
return bUpdate;
Expand Down Expand Up @@ -2668,13 +2668,13 @@ bool CvPlayerCulture::FillBuilding(vector<CvGreatWorkBuildingInMyEmpire>::const_

worksToConsider = works1;
vector<CvGreatWorkInMyEmpire>::const_iterator it;
for (it = works2.begin(); it != works2.end(); it++)
for (it = works2.begin(); it != works2.end(); ++it)
{
worksToConsider.push_back(*it);
}

it = worksToConsider.begin();
for (int iI = 0; iI < iCountSlots && it != worksToConsider.end(); iI++, it++)
for (int iI = 0; iI < iCountSlots && it != worksToConsider.end(); iI++, ++it)
{
aWorksChosen.push_back(worksToConsider[iI].m_iGreatWorkIndex);
// CUSTOMLOG(" filling slot %i with Great Work %i", iI, worksToConsider[iI].m_iGreatWorkIndex);
Expand Down
2 changes: 1 addition & 1 deletion CvGameCoreDLL_Expansion2/CvDealAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ int CvDealAI::GetLuxuryResourceValue(ResourceTypes eResource, int iNumTurns, boo
if (!pMinorAI->IsActiveQuestForPlayer(GetPlayer()->GetID(), MINOR_CIV_QUEST_CONNECT_RESOURCE))
continue;

for (QuestListForPlayer::iterator itr_quest = pMinorAI->m_QuestsGiven[GetPlayer()->GetID()].begin(); itr_quest != pMinorAI->m_QuestsGiven[GetPlayer()->GetID()].end(); itr_quest++)
for (QuestListForPlayer::iterator itr_quest = pMinorAI->m_QuestsGiven[GetPlayer()->GetID()].begin(); itr_quest != pMinorAI->m_QuestsGiven[GetPlayer()->GetID()].end(); ++itr_quest)
{
if (itr_quest->GetType() == MINOR_CIV_QUEST_CONNECT_RESOURCE && (ResourceTypes)itr_quest->GetPrimaryData() == eResource)
{
Expand Down
8 changes: 4 additions & 4 deletions CvGameCoreDLL_Expansion2/CvDealClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,7 @@ CvString CvDeal::GetReasonsItemUntradeable(PlayerTypes ePlayer, PlayerTypes eToP
bool CvDeal::ContainsItemType(TradeableItems eItemType, PlayerTypes eFrom /* = NO_PLAYER */, ResourceTypes eResource /* = NO_RESOURCE */)
{
TradedItemList::iterator it;
for (it = m_TradedItems.begin(); it != m_TradedItems.end(); it++)
for (it = m_TradedItems.begin(); it != m_TradedItems.end(); ++it)
{
if (it->m_eItemType == eItemType && (eFrom == NO_PLAYER || it->m_eFromPlayer == eFrom))
{
Expand All @@ -3034,7 +3034,7 @@ bool CvDeal::ContainsItemType(TradeableItems eItemType, PlayerTypes eFrom /* = N
bool CvDeal::ContainsItemTypes(vector<TradeableItems> vItemTypes, PlayerTypes eFrom /* = NO_PLAYER */)
{
TradedItemList::iterator it;
for (it = m_TradedItems.begin(); it != m_TradedItems.end(); it++)
for (it = m_TradedItems.begin(); it != m_TradedItems.end(); ++it)
{
if (eFrom == NO_PLAYER || it->m_eFromPlayer == eFrom)
{
Expand Down Expand Up @@ -4398,7 +4398,7 @@ void CvGameDeals::ActivateDeal(PlayerTypes eFromPlayer, PlayerTypes eToPlayer, C
bool bFromPlayerItem = false;
bool bToPlayerItem = false;

for (TradedItemList::iterator it = kDeal.m_TradedItems.begin(); it != kDeal.m_TradedItems.end(); it++)
for (TradedItemList::iterator it = kDeal.m_TradedItems.begin(); it != kDeal.m_TradedItems.end(); ++it)
{
if (it->m_iDuration > 0)
{
Expand Down Expand Up @@ -4464,7 +4464,7 @@ void CvGameDeals::ActivateDeal(PlayerTypes eFromPlayer, PlayerTypes eToPlayer, C
bool bDoWarVictoryBonuses = true;

// Process each item in the deal!
for (TradedItemList::iterator it = kDeal.m_TradedItems.begin(); it != kDeal.m_TradedItems.end(); it++)
for (TradedItemList::iterator it = kDeal.m_TradedItems.begin(); it != kDeal.m_TradedItems.end(); ++it)
{
if (it->m_eItemType == TRADE_ITEM_NONE)
continue;
Expand Down
Loading

0 comments on commit 9ad006c

Please sign in to comment.