From 4b19b15936faa8e1d5f331cc11147ccfc360bde7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 20 Sep 2013 20:50:50 +0300 Subject: improve a bit code speed. --- src/resources/beinginfo.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/resources/beinginfo.cpp') diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 48e8b8493..84d32f623 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -77,7 +77,7 @@ BeingInfo::~BeingInfo() delete_all(mDisplay.sprites); } -void BeingInfo::setDisplay(SpriteDisplay display) +void BeingInfo::setDisplay(const SpriteDisplay &display) { mDisplay = display; } @@ -119,8 +119,15 @@ const SoundInfo &BeingInfo::getSound(const SoundEvent event) const static SoundInfo emptySound("", 0); const SoundEvents::const_iterator i = mSounds.find(event); - return (i == mSounds.end() || !i->second || i->second->empty()) - ? emptySound : i->second->at(rand() % i->second->size()); + + if (i == mSounds.end()) + return emptySound; + + const SoundInfoVect *const vect = i->second; + if (!vect || vect->empty()) + return emptySound; + else + return vect->at(rand() % vect->size()); } const Attack *BeingInfo::getAttack(const int id) const -- cgit v1.2.3-60-g2f50