Avoid copying the same Ptr with each iteration

experimental
Chris Robinson 7 years ago
parent edfba68eb5
commit 6f57233ba1

@ -1005,11 +1005,14 @@ namespace MWSound
SoundMap::iterator snditer = mActiveSounds.begin(); SoundMap::iterator snditer = mActiveSounds.begin();
while(snditer != mActiveSounds.end()) while(snditer != mActiveSounds.end())
{ {
MWWorld::ConstPtr ptr = snditer->first;
SoundBufferRefPairList::iterator sndidx = snditer->second.begin(); SoundBufferRefPairList::iterator sndidx = snditer->second.begin();
while(sndidx != snditer->second.end()) while(sndidx != snditer->second.end())
{ {
MWWorld::ConstPtr ptr = snditer->first; Sound *sound;
Sound *sound = sndidx->first; Sound_Buffer *sfx;
std::tie(sound, sfx) = *sndidx;
if(!ptr.isEmpty() && sound->getIs3D()) if(!ptr.isEmpty() && sound->getIs3D())
{ {
const ESM::Position &pos = ptr.getRefData().getPosition(); const ESM::Position &pos = ptr.getRefData().getPosition();
@ -1031,7 +1034,6 @@ namespace MWSound
mUnderwaterSound = nullptr; mUnderwaterSound = nullptr;
if(sound == mNearWaterSound) if(sound == mNearWaterSound)
mNearWaterSound = nullptr; mNearWaterSound = nullptr;
Sound_Buffer *sfx = sndidx->second;
if(sfx->mUses-- == 1) if(sfx->mUses-- == 1)
mUnusedBuffers.push_front(sfx); mUnusedBuffers.push_front(sfx);
sndidx = snditer->second.erase(sndidx); sndidx = snditer->second.erase(sndidx);
@ -1045,7 +1047,7 @@ namespace MWSound
} }
} }
if(snditer->second.empty()) if(snditer->second.empty())
mActiveSounds.erase(snditer++); snditer = mActiveSounds.erase(snditer);
else else
++snditer; ++snditer;
} }

Loading…
Cancel
Save