mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Pass functor via reference to avoid costly copies
This commit is contained in:
@@ -298,7 +298,7 @@ std::shared_ptr<StackWithBonuses> HypotheticBattle::getForUpdate(uint32_t id)
|
||||
}
|
||||
}
|
||||
|
||||
battle::Units HypotheticBattle::getUnitsIf(battle::UnitFilter predicate) const
|
||||
battle::Units HypotheticBattle::getUnitsIf(const battle::UnitFilter & predicate) const
|
||||
{
|
||||
battle::Units proxyed = BattleProxy::getUnitsIf(predicate);
|
||||
|
||||
|
@@ -114,7 +114,7 @@ public:
|
||||
|
||||
int32_t getActiveStackID() const override;
|
||||
|
||||
battle::Units getUnitsIf(battle::UnitFilter predicate) const override;
|
||||
battle::Units getUnitsIf(const battle::UnitFilter & predicate) const override;
|
||||
|
||||
void nextRound() override;
|
||||
void nextTurn(uint32_t unitId) override;
|
||||
|
@@ -562,14 +562,14 @@ int32_t BattleInfo::getActiveStackID() const
|
||||
return activeStack;
|
||||
}
|
||||
|
||||
TStacks BattleInfo::getStacksIf(TStackFilter predicate) const
|
||||
TStacks BattleInfo::getStacksIf(const TStackFilter & predicate) const
|
||||
{
|
||||
TStacks ret;
|
||||
vstd::copy_if(stacks, std::back_inserter(ret), predicate);
|
||||
return ret;
|
||||
}
|
||||
|
||||
battle::Units BattleInfo::getUnitsIf(battle::UnitFilter predicate) const
|
||||
battle::Units BattleInfo::getUnitsIf(const battle::UnitFilter & predicate) const
|
||||
{
|
||||
battle::Units ret;
|
||||
vstd::copy_if(stacks, std::back_inserter(ret), predicate);
|
||||
|
@@ -85,9 +85,9 @@ public:
|
||||
|
||||
int32_t getActiveStackID() const override;
|
||||
|
||||
TStacks getStacksIf(TStackFilter predicate) const override;
|
||||
TStacks getStacksIf(const TStackFilter & predicate) const override;
|
||||
|
||||
battle::Units getUnitsIf(battle::UnitFilter predicate) const override;
|
||||
battle::Units getUnitsIf(const battle::UnitFilter & predicate) const override;
|
||||
|
||||
BattleField getBattlefieldType() const override;
|
||||
TerrainId getTerrainType() const override;
|
||||
|
@@ -40,12 +40,12 @@ int32_t BattleProxy::getActiveStackID() const
|
||||
return -1;
|
||||
}
|
||||
|
||||
TStacks BattleProxy::getStacksIf(TStackFilter predicate) const
|
||||
TStacks BattleProxy::getStacksIf(const TStackFilter & predicate) const
|
||||
{
|
||||
return subject->battleGetStacksIf(predicate);
|
||||
}
|
||||
|
||||
battle::Units BattleProxy::getUnitsIf(battle::UnitFilter predicate) const
|
||||
battle::Units BattleProxy::getUnitsIf(const battle::UnitFilter & predicate) const
|
||||
{
|
||||
return subject->battleGetUnitsIf(predicate);
|
||||
}
|
||||
|
@@ -29,9 +29,9 @@ public:
|
||||
|
||||
int32_t getActiveStackID() const override;
|
||||
|
||||
TStacks getStacksIf(TStackFilter predicate) const override;
|
||||
TStacks getStacksIf(const TStackFilter & predicate) const override;
|
||||
|
||||
battle::Units getUnitsIf(battle::UnitFilter predicate) const override;
|
||||
battle::Units getUnitsIf(const battle::UnitFilter & predicate) const override;
|
||||
|
||||
BattleField getBattlefieldType() const override;
|
||||
TerrainId getTerrainType() const override;
|
||||
|
@@ -109,13 +109,13 @@ TStacks CBattleInfoEssentials::battleGetAllStacks(bool includeTurrets) const
|
||||
});
|
||||
}
|
||||
|
||||
TStacks CBattleInfoEssentials::battleGetStacksIf(TStackFilter predicate) const
|
||||
TStacks CBattleInfoEssentials::battleGetStacksIf(const TStackFilter & predicate) const
|
||||
{
|
||||
RETURN_IF_NOT_BATTLE(TStacks());
|
||||
return getBattle()->getStacksIf(std::move(predicate));
|
||||
}
|
||||
|
||||
battle::Units CBattleInfoEssentials::battleGetUnitsIf(battle::UnitFilter predicate) const
|
||||
battle::Units CBattleInfoEssentials::battleGetUnitsIf(const battle::UnitFilter & predicate) const
|
||||
{
|
||||
RETURN_IF_NOT_BATTLE(battle::Units());
|
||||
return getBattle()->getUnitsIf(predicate);
|
||||
|
@@ -62,8 +62,8 @@ public:
|
||||
* @return filtered stacks
|
||||
*
|
||||
*/
|
||||
TStacks battleGetStacksIf(TStackFilter predicate) const; //deprecated
|
||||
battle::Units battleGetUnitsIf(battle::UnitFilter predicate) const override;
|
||||
TStacks battleGetStacksIf(const TStackFilter & predicate) const; //deprecated
|
||||
battle::Units battleGetUnitsIf(const battle::UnitFilter & predicate) const override;
|
||||
|
||||
const battle::Unit * battleGetUnitByID(uint32_t ID) const override;
|
||||
const battle::Unit * battleActiveUnit() const override;
|
||||
|
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
virtual uint32_t battleNextUnitId() const = 0;
|
||||
|
||||
virtual battle::Units battleGetUnitsIf(battle::UnitFilter predicate) const = 0;
|
||||
virtual battle::Units battleGetUnitsIf(const battle::UnitFilter & predicate) const = 0;
|
||||
|
||||
virtual const battle::Unit * battleGetUnitByID(uint32_t ID) const = 0;
|
||||
virtual const battle::Unit * battleGetUnitByPos(BattleHex pos, bool onlyAlive = true) const = 0;
|
||||
|
@@ -42,9 +42,9 @@ public:
|
||||
|
||||
virtual int32_t getActiveStackID() const = 0;
|
||||
|
||||
virtual TStacks getStacksIf(TStackFilter predicate) const = 0;
|
||||
virtual TStacks getStacksIf(const TStackFilter & predicate) const = 0;
|
||||
|
||||
virtual battle::Units getUnitsIf(battle::UnitFilter predicate) const = 0;
|
||||
virtual battle::Units getUnitsIf(const battle::UnitFilter & predicate) const = 0;
|
||||
|
||||
virtual BattleField getBattlefieldType() const = 0;
|
||||
virtual TerrainId getTerrainType() const = 0;
|
||||
|
Reference in New Issue
Block a user