forked from mirror/openmw-tes3mp
minor performance improvements in apps/openmw
Checking for emptiness using size() might be inefficient, because it can take linear time, while empty() is guaranteed to take only constant time. For non-primitive types, postfix ++ operators are inefficient compared to prefix ++ operators, because post-increment usually involves keeping a copy of the previous value around.
This commit is contained in:
parent
ca097e146b
commit
1b8c975d5b
14 changed files with 43 additions and 44 deletions
|
@ -78,13 +78,13 @@ namespace MWGui
|
|||
}
|
||||
|
||||
void TradeWindow::startTrade(const MWWorld::Ptr& actor)
|
||||
{
|
||||
{
|
||||
mPtr = actor;
|
||||
|
||||
mCurrentBalance = 0;
|
||||
mCurrentMerchantOffer = 0;
|
||||
|
||||
checkTradeTime();
|
||||
checkTradeTime();
|
||||
|
||||
std::vector<MWWorld::Ptr> itemSources;
|
||||
MWBase::Environment::get().getWorld()->getContainersOwnedBy(actor, itemSources);
|
||||
|
@ -245,7 +245,7 @@ namespace MWGui
|
|||
// were there any items traded at all?
|
||||
std::vector<ItemStack> playerBought = playerItemModel->getItemsBorrowedToUs();
|
||||
std::vector<ItemStack> merchantBought = mTradeModel->getItemsBorrowedToUs();
|
||||
if (!playerBought.size() && !merchantBought.size())
|
||||
if (playerBought.empty() && merchantBought.empty())
|
||||
{
|
||||
// user notification
|
||||
MWBase::Environment::get().getWindowManager()->
|
||||
|
@ -476,7 +476,7 @@ namespace MWGui
|
|||
}
|
||||
|
||||
// Relates to NPC gold reset delay
|
||||
void TradeWindow::checkTradeTime()
|
||||
void TradeWindow::checkTradeTime()
|
||||
{
|
||||
MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr);
|
||||
double delay = boost::lexical_cast<double>(MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fBarterGoldResetDelay")->getInt());
|
||||
|
@ -488,14 +488,14 @@ namespace MWGui
|
|||
}
|
||||
}
|
||||
|
||||
void TradeWindow::updateTradeTime()
|
||||
void TradeWindow::updateTradeTime()
|
||||
{
|
||||
MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr);
|
||||
MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr);
|
||||
double delay = boost::lexical_cast<double>(MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fBarterGoldResetDelay")->getInt());
|
||||
|
||||
// If trade timestamp is within reset delay don't set
|
||||
if ( ! (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getTradeTime() &&
|
||||
if ( ! (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getTradeTime() &&
|
||||
MWBase::Environment::get().getWorld()->getTimeStamp() < sellerStats.getTradeTime() + delay) )
|
||||
{
|
||||
sellerStats.setTradeTime(MWBase::Environment::get().getWorld()->getTimeStamp());
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace MWMechanics
|
|||
if (effectIt->mKey.mId == effectId)
|
||||
effectIt = it->second.mEffects.erase(effectIt);
|
||||
else
|
||||
effectIt++;
|
||||
++effectIt;
|
||||
}
|
||||
}
|
||||
mSpellsChanged = true;
|
||||
|
@ -224,7 +224,7 @@ namespace MWMechanics
|
|||
&& it->second.mCasterHandle == actorHandle)
|
||||
effectIt = it->second.mEffects.erase(effectIt);
|
||||
else
|
||||
effectIt++;
|
||||
++effectIt;
|
||||
}
|
||||
}
|
||||
mSpellsChanged = true;
|
||||
|
|
|
@ -38,7 +38,7 @@ MWMechanics::AiSequence& MWMechanics::AiSequence::operator= (const AiSequence& s
|
|||
copy (sequence);
|
||||
mDone = sequence.mDone;
|
||||
}
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ int MWMechanics::AiSequence::getTypeId() const
|
|||
{
|
||||
if (mPackages.empty())
|
||||
return -1;
|
||||
|
||||
|
||||
return mPackages.front()->getTypeId();
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ void MWMechanics::AiSequence::execute (const MWWorld::Ptr& actor,float duration)
|
|||
}
|
||||
else
|
||||
{
|
||||
mDone = false;
|
||||
mDone = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ void MWMechanics::AiSequence::clear()
|
|||
|
||||
void MWMechanics::AiSequence::stack (const AiPackage& package)
|
||||
{
|
||||
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end(); it++)
|
||||
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end(); ++it)
|
||||
{
|
||||
if(mPackages.front()->getPriority() <= package.getPriority())
|
||||
{
|
||||
|
|
|
@ -296,7 +296,7 @@ namespace MWMechanics
|
|||
// add this edge to openset, lowest cost goes to the front
|
||||
// TODO: if this causes performance problems a hash table may help
|
||||
std::list<int>::iterator it = openset.begin();
|
||||
for(it = openset.begin(); it!= openset.end(); it++)
|
||||
for(it = openset.begin(); it!= openset.end(); ++it)
|
||||
{
|
||||
if(fScore[*it] > fScore[dest])
|
||||
break;
|
||||
|
|
|
@ -401,10 +401,10 @@ namespace MWMechanics
|
|||
if (!exploded)
|
||||
MWBase::Environment::get().getWorld()->explodeSpell(mHitPosition, mTarget, effects, caster, mId, mSourceName);
|
||||
|
||||
if (reflectedEffects.mList.size())
|
||||
if (!reflectedEffects.mList.empty())
|
||||
inflict(caster, target, reflectedEffects, range, true);
|
||||
|
||||
if (appliedLastingEffects.size())
|
||||
if (!appliedLastingEffects.empty())
|
||||
target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects,
|
||||
mSourceName, caster.getRefData().getHandle());
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ namespace MWMechanics
|
|||
if (spell->mData.mType == ESM::Spell::ST_Disease)
|
||||
mSpells.erase(iter++);
|
||||
else
|
||||
iter++;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ namespace MWMechanics
|
|||
if (spell->mData.mType == ESM::Spell::ST_Blight)
|
||||
mSpells.erase(iter++);
|
||||
else
|
||||
iter++;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ namespace MWMechanics
|
|||
if (Misc::StringUtils::ciEqual(spell->mId, "corprus"))
|
||||
mSpells.erase(iter++);
|
||||
else
|
||||
iter++;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ namespace MWMechanics
|
|||
if (spell->mData.mType == ESM::Spell::ST_Curse)
|
||||
mSpells.erase(iter++);
|
||||
else
|
||||
iter++;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -411,7 +411,7 @@ Ogre::Node *Animation::getNode(const std::string &name)
|
|||
NifOgre::TextKeyMap::const_iterator Animation::findGroupStart(const NifOgre::TextKeyMap &keys, const std::string &groupname)
|
||||
{
|
||||
NifOgre::TextKeyMap::const_iterator iter(keys.begin());
|
||||
for(;iter != keys.end();iter++)
|
||||
for(;iter != keys.end();++iter)
|
||||
{
|
||||
if(iter->second.compare(0, groupname.size(), groupname) == 0 &&
|
||||
iter->second.compare(groupname.size(), 2, ": ") == 0)
|
||||
|
@ -424,7 +424,7 @@ NifOgre::TextKeyMap::const_iterator Animation::findGroupStart(const NifOgre::Tex
|
|||
bool Animation::hasAnimation(const std::string &anim)
|
||||
{
|
||||
AnimSourceList::const_iterator iter(mAnimSources.begin());
|
||||
for(;iter != mAnimSources.end();iter++)
|
||||
for(;iter != mAnimSources.end();++iter)
|
||||
{
|
||||
const NifOgre::TextKeyMap &keys = (*iter)->mTextKeys;
|
||||
if(findGroupStart(keys, anim) != keys.end())
|
||||
|
@ -465,7 +465,7 @@ float Animation::calcAnimVelocity(const NifOgre::TextKeyMap &keys, NifOgre::Node
|
|||
stoptime = keyiter->first;
|
||||
break;
|
||||
}
|
||||
keyiter++;
|
||||
++keyiter;
|
||||
}
|
||||
|
||||
if(stoptime > starttime)
|
||||
|
@ -585,13 +585,13 @@ bool Animation::reset(AnimState &state, const NifOgre::TextKeyMap &keys, const s
|
|||
std::string starttag = groupname+": "+start;
|
||||
NifOgre::TextKeyMap::const_iterator startkey(groupstart);
|
||||
while(startkey != keys.end() && startkey->second != starttag)
|
||||
startkey++;
|
||||
++startkey;
|
||||
if(startkey == keys.end() && start == "loop start")
|
||||
{
|
||||
starttag = groupname+": start";
|
||||
startkey = groupstart;
|
||||
while(startkey != keys.end() && startkey->second != starttag)
|
||||
startkey++;
|
||||
++startkey;
|
||||
}
|
||||
if(startkey == keys.end())
|
||||
return false;
|
||||
|
@ -603,7 +603,7 @@ bool Animation::reset(AnimState &state, const NifOgre::TextKeyMap &keys, const s
|
|||
// The Scrib's idle3 animation has "Idle3: Stop." instead of "Idle3: Stop".
|
||||
// Why, just why? :(
|
||||
&& (stopkey->second.size() < stoptag.size() || stopkey->second.substr(0,stoptag.size()) != stoptag))
|
||||
stopkey++;
|
||||
++stopkey;
|
||||
if(stopkey == keys.end())
|
||||
return false;
|
||||
|
||||
|
@ -627,7 +627,7 @@ bool Animation::reset(AnimState &state, const NifOgre::TextKeyMap &keys, const s
|
|||
state.mLoopStartTime = key->first;
|
||||
else if(key->second == loopstoptag)
|
||||
state.mLoopStopTime = key->first;
|
||||
key++;
|
||||
++key;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -776,7 +776,7 @@ void Animation::play(const std::string &groupname, int priority, int groups, boo
|
|||
|
||||
/* Look in reverse; last-inserted source has priority. */
|
||||
AnimSourceList::reverse_iterator iter(mAnimSources.rbegin());
|
||||
for(;iter != mAnimSources.rend();iter++)
|
||||
for(;iter != mAnimSources.rend();++iter)
|
||||
{
|
||||
const NifOgre::TextKeyMap &textkeys = (*iter)->mTextKeys;
|
||||
AnimState state;
|
||||
|
@ -795,7 +795,7 @@ void Animation::play(const std::string &groupname, int priority, int groups, boo
|
|||
while(textkey != textkeys.end() && textkey->first <= state.mTime)
|
||||
{
|
||||
handleTextKey(state, groupname, textkey);
|
||||
textkey++;
|
||||
++textkey;
|
||||
}
|
||||
|
||||
if(state.mTime >= state.mLoopStopTime && state.mLoopCount > 0)
|
||||
|
@ -810,7 +810,7 @@ void Animation::play(const std::string &groupname, int priority, int groups, boo
|
|||
while(textkey != textkeys.end() && textkey->first <= state.mTime)
|
||||
{
|
||||
handleTextKey(state, groupname, textkey);
|
||||
textkey++;
|
||||
++textkey;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -965,7 +965,7 @@ Ogre::Vector3 Animation::runAnimation(float duration)
|
|||
while(textkey != textkeys.end() && textkey->first <= state.mTime)
|
||||
{
|
||||
handleTextKey(state, stateiter->first, textkey);
|
||||
textkey++;
|
||||
++textkey;
|
||||
}
|
||||
|
||||
if(state.mTime >= state.mLoopStopTime && state.mLoopCount > 0)
|
||||
|
@ -979,7 +979,7 @@ Ogre::Vector3 Animation::runAnimation(float duration)
|
|||
while(textkey != textkeys.end() && textkey->first <= state.mTime)
|
||||
{
|
||||
handleTextKey(state, stateiter->first, textkey);
|
||||
textkey++;
|
||||
++textkey;
|
||||
}
|
||||
|
||||
if(state.mTime >= state.mLoopStopTime)
|
||||
|
|
|
@ -106,7 +106,7 @@ ManualObject *Debugging::createPathgridPoints(const ESM::Pathgrid *pathgrid)
|
|||
uint32 startIndex = 0;
|
||||
for(ESM::Pathgrid::PointList::const_iterator it = pathgrid->mPoints.begin();
|
||||
it != pathgrid->mPoints.end();
|
||||
it++, startIndex += 6)
|
||||
++it, startIndex += 6)
|
||||
{
|
||||
Vector3 pointPos(it->mX, it->mY, it->mZ);
|
||||
|
||||
|
|
|
@ -240,25 +240,25 @@ Ogre::AxisAlignedBox Objects::getDimensions(MWWorld::CellStore* cell)
|
|||
void Objects::enableLights()
|
||||
{
|
||||
PtrAnimationMap::const_iterator it = mObjects.begin();
|
||||
for(;it != mObjects.end();it++)
|
||||
for(;it != mObjects.end();++it)
|
||||
it->second->enableLights(true);
|
||||
}
|
||||
|
||||
void Objects::disableLights()
|
||||
{
|
||||
PtrAnimationMap::const_iterator it = mObjects.begin();
|
||||
for(;it != mObjects.end();it++)
|
||||
for(;it != mObjects.end();++it)
|
||||
it->second->enableLights(false);
|
||||
}
|
||||
|
||||
void Objects::update(float dt, Ogre::Camera* camera)
|
||||
{
|
||||
PtrAnimationMap::const_iterator it = mObjects.begin();
|
||||
for(;it != mObjects.end();it++)
|
||||
for(;it != mObjects.end();++it)
|
||||
it->second->runAnimation(dt);
|
||||
|
||||
it = mObjects.begin();
|
||||
for(;it != mObjects.end();it++)
|
||||
for(;it != mObjects.end();++it)
|
||||
it->second->preRender(camera);
|
||||
|
||||
}
|
||||
|
|
|
@ -442,7 +442,7 @@ namespace MWSound
|
|||
{
|
||||
snditer->first->setFadeout(duration);
|
||||
}
|
||||
snditer++;
|
||||
++snditer;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace MWWorld
|
|||
|
||||
//find any NPC that is following the actor and teleport him too
|
||||
std::list<MWWorld::Ptr> followers = MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(actor);
|
||||
for(std::list<MWWorld::Ptr>::iterator it = followers.begin();it != followers.end();it++)
|
||||
for(std::list<MWWorld::Ptr>::iterator it = followers.begin();it != followers.end();++it)
|
||||
{
|
||||
std::cout << "teleporting someone!" << (*it).getCellRef().mRefID;
|
||||
executeImp(*it);
|
||||
|
|
|
@ -433,7 +433,6 @@ namespace MWWorld
|
|||
while(mCell->getNextRef(esm[index], ref, deleted))
|
||||
{
|
||||
// Don't load reference if it was moved to a different cell.
|
||||
std::string lowerCase = Misc::StringUtils::lowerCase(ref.mRefID);
|
||||
ESM::MovedCellRefTracker::const_iterator iter =
|
||||
std::find(mCell->mMovedRefs.begin(), mCell->mMovedRefs.end(), ref.mRefNum);
|
||||
if (iter != mCell->mMovedRefs.end()) {
|
||||
|
|
|
@ -671,7 +671,7 @@ namespace MWWorld
|
|||
void PhysicsSystem::queueObjectMovement(const Ptr &ptr, const Ogre::Vector3 &movement)
|
||||
{
|
||||
PtrVelocityList::iterator iter = mMovementQueue.begin();
|
||||
for(;iter != mMovementQueue.end();iter++)
|
||||
for(;iter != mMovementQueue.end();++iter)
|
||||
{
|
||||
if(iter->first == ptr)
|
||||
{
|
||||
|
@ -692,7 +692,7 @@ namespace MWWorld
|
|||
{
|
||||
const MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
PtrVelocityList::iterator iter = mMovementQueue.begin();
|
||||
for(;iter != mMovementQueue.end();iter++)
|
||||
for(;iter != mMovementQueue.end();++iter)
|
||||
{
|
||||
float waterlevel = -std::numeric_limits<float>::max();
|
||||
const ESM::Cell *cell = iter->first.getCell()->getCell();
|
||||
|
|
|
@ -141,17 +141,17 @@ namespace MWWorld
|
|||
|
||||
// Find all the actors who might be able to see the player
|
||||
std::vector<MWWorld::Ptr> neighbors;
|
||||
MWBase::Environment::get().getMechanicsManager()->getActorsInRange( Ogre::Vector3(ptr.getRefData().getPosition().pos),
|
||||
MWBase::Environment::get().getMechanicsManager()->getActorsInRange( Ogre::Vector3(ptr.getRefData().getPosition().pos),
|
||||
esmStore.get<ESM::GameSetting>().find("fSneakUseDist")->getInt(), neighbors);
|
||||
for (std::vector<MWWorld::Ptr>::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
|
||||
{
|
||||
if ( MWBase::Environment::get().getMechanicsManager()->awarenessCheck(ptr, *it) )
|
||||
{
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->setSneakVisibility(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (neighbors.size() == 0)
|
||||
if (neighbors.empty())
|
||||
MWBase::Environment::get().getWindowManager()->setSneakVisibility(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue