1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-13 11:40:38 +02:00

Small micro-optimizations for code that gets called A LOT

This commit is contained in:
Ivan Savenko 2024-12-18 13:39:05 +00:00
parent b8a04c6356
commit 4f80ccd648
3 changed files with 10 additions and 5 deletions

View File

@ -48,12 +48,15 @@ template <class _ObjectID, class _ObjectBase, class _Object, class _ServiceBase>
{
const _Object * getObjectImpl(const int32_t index) const
{
if(index < 0 || index >= objects.size())
try
{
return objects.at(index).get();
}
catch (const std::out_of_range&)
{
logMod->error("%s id %d is invalid", getTypeNames()[0], index);
throw std::runtime_error("Attempt to access invalid index " + std::to_string(index) + " of type " + getTypeNames().front());
}
return objects[index].get();
}
public:

View File

@ -711,6 +711,9 @@ bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker) const
if (attacker->creatureIndex() == CreatureID::CATAPULT) //catapult cannot attack creatures
return false;
if (!attacker->canShoot())
return false;
//forgetfulness
TConstBonusListPtr forgetfulList = attacker->getBonuses(Selector::type()(BonusType::FORGETFULL));
if(!forgetfulList->empty())
@ -722,8 +725,7 @@ bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker) const
return false;
}
return attacker->canShoot() && (!battleIsUnitBlocked(attacker)
|| attacker->hasBonusOfType(BonusType::FREE_SHOOTING));
return !battleIsUnitBlocked(attacker) || attacker->hasBonusOfType(BonusType::FREE_SHOOTING);
}
bool CBattleInfoCallback::battleCanTargetEmptyHex(const battle::Unit * attacker) const

View File

@ -325,7 +325,7 @@ const Skill * SecondarySkill::toEntity(const Services * services) const
const CCreature * CreatureIDBase::toCreature() const
{
return dynamic_cast<const CCreature *>(toEntity(VLC));
return (*VLC->creh)[num];
}
const Creature * CreatureIDBase::toEntity(const Services * services) const