diff --git a/indra/llcharacter/llcharacter.cpp b/indra/llcharacter/llcharacter.cpp index 888c20cd4..68ce69758 100644 --- a/indra/llcharacter/llcharacter.cpp +++ b/indra/llcharacter/llcharacter.cpp @@ -72,21 +72,11 @@ LLCharacter::~LLCharacter() delete param; } - U32 i ; - U32 size = sInstances.size() ; - for(i = 0 ; i < size ; i++) - { - if(sInstances[i] == this) - { - break ; - } - } + bool erased = vector_replace_with_last(sInstances,this); - llassert_always(i < size) ; + llassert_always(erased) ; llassert_always(sAllowInstancesChange) ; - sInstances[i] = sInstances[size - 1] ; - sInstances.pop_back() ; } diff --git a/indra/newview/lldrawpool.cpp b/indra/newview/lldrawpool.cpp index 53b13d693..7a6ca0e24 100644 --- a/indra/newview/lldrawpool.cpp +++ b/indra/newview/lldrawpool.cpp @@ -297,17 +297,14 @@ LLViewerTexture *LLFacePool::getTexture() void LLFacePool::removeFaceReference(LLFace *facep) { - if (facep->getReferenceIndex() != -1) + S32 idx = facep->getReferenceIndex(); + if (idx != -1) { - if (facep->getReferenceIndex() != (S32)mReferences.size()) - { - LLFace *back = mReferences.back(); - mReferences[facep->getReferenceIndex()] = back; - back->setReferenceIndex(facep->getReferenceIndex()); - } - mReferences.pop_back(); + facep->setReferenceIndex(-1); + std::vector::iterator iter = vector_replace_with_last(mReferences, mReferences.begin() + idx); + if(iter != mReferences.end()) + (*iter)->setReferenceIndex(idx); } - facep->setReferenceIndex(-1); } void LLFacePool::addFaceReference(LLFace *facep) diff --git a/indra/newview/llflexibleobject.cpp b/indra/newview/llflexibleobject.cpp index 12b8da94f..e378c4458 100644 --- a/indra/newview/llflexibleobject.cpp +++ b/indra/newview/llflexibleobject.cpp @@ -80,17 +80,10 @@ LLVolumeImplFlexible::LLVolumeImplFlexible(LLViewerObject* vo, LLFlexibleObjectD LLVolumeImplFlexible::~LLVolumeImplFlexible() { - S32 end_idx = sInstanceList.size()-1; - - if (end_idx != mInstanceIndex) - { - sInstanceList[mInstanceIndex] = sInstanceList[end_idx]; - sInstanceList[mInstanceIndex]->mInstanceIndex = mInstanceIndex; - sUpdateDelay[mInstanceIndex] = sUpdateDelay[end_idx]; - } - - sInstanceList.pop_back(); - sUpdateDelay.pop_back(); + std::vector::iterator iter = vector_replace_with_last(sInstanceList, sInstanceList.begin() + mInstanceIndex); + if(iter != sInstanceList.end()) + (*iter)->mInstanceIndex = mInstanceIndex; + vector_replace_with_last(sUpdateDelay,sUpdateDelay.begin() + mInstanceIndex); } //static diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp index 4ae625a52..e42de793e 100644 --- a/indra/newview/llviewerobjectlist.cpp +++ b/indra/newview/llviewerobjectlist.cpp @@ -1459,15 +1459,10 @@ void LLViewerObjectList::removeFromActiveList(LLViewerObject* objectp) objectp->setListIndex(-1); - S32 last_index = mActiveObjects.size()-1; + std::vector >::iterator iter = vector_replace_with_last(mActiveObjects,mActiveObjects.begin() + idx); + if(iter != mActiveObjects.end()) + (*iter)->setListIndex(idx); - if (idx != last_index) - { - mActiveObjects[idx] = mActiveObjects[last_index]; - mActiveObjects[idx]->setListIndex(idx); - } - - mActiveObjects.pop_back(); } } diff --git a/indra/newview/llviewerpartsim.cpp b/indra/newview/llviewerpartsim.cpp index 8f07858cf..a27e1ec4e 100644 --- a/indra/newview/llviewerpartsim.cpp +++ b/indra/newview/llviewerpartsim.cpp @@ -406,8 +406,7 @@ void LLViewerPartGroup::updateParticles(const F32 lastdt) // Kill dead particles (either flagged dead, or too old) if ((part->mLastUpdateTime > part->mMaxAge) || (LLViewerPart::LL_PART_DEAD_MASK == part->mFlags)) { - mParticles[i] = mParticles.back() ; - mParticles.pop_back() ; + vector_replace_with_last(mParticles,mParticles.begin() + i); delete part ; } else @@ -417,8 +416,7 @@ void LLViewerPartGroup::updateParticles(const F32 lastdt) { // Transfer particles between groups LLViewerPartSim::getInstance()->put(part) ; - mParticles[i] = mParticles.back() ; - mParticles.pop_back() ; + vector_replace_with_last(mParticles,mParticles.begin() + i); } else { @@ -675,11 +673,9 @@ void LLViewerPartSim::updateSimulation() S32 count = (S32) mViewerPartSources.size(); S32 start = (S32)ll_frand((F32)count); S32 dir = 1; - S32 deldir = 0; if (ll_frand() > 0.5f) { dir = -1; - deldir = -1; } S32 num_updates = 0; @@ -725,11 +721,9 @@ void LLViewerPartSim::updateSimulation() if (mViewerPartSources[i]->isDead()) { - mViewerPartSources[i] = mViewerPartSources.back(); - mViewerPartSources.pop_back(); + vector_replace_with_last(mViewerPartSources,mViewerPartSources.begin() + i); //mViewerPartSources.erase(mViewerPartSources.begin() + i); count--; - i+=deldir; } else { @@ -764,8 +758,7 @@ void LLViewerPartSim::updateSimulation() if (!mViewerPartGroups[i]->getCount()) { delete mViewerPartGroups[i]; - mViewerPartGroups[i] = mViewerPartGroups.back(); - mViewerPartGroups.pop_back(); + vector_replace_with_last(mViewerPartGroups,mViewerPartGroups.begin() + i); //mViewerPartGroups.erase(mViewerPartGroups.begin() + i); i--; count--; @@ -849,15 +842,15 @@ void LLViewerPartSim::removeLastCreatedSource() void LLViewerPartSim::cleanupRegion(LLViewerRegion *regionp) { group_list_t& vec = mViewerPartGroups; - for (group_list_t::size_type i = 0;igetRegion() == regionp) + if ((*it)->getRegion() == regionp) { - delete vec[i]; - vec[i--] = vec.back(); - vec.pop_back(); + delete *it; + it = vector_replace_with_last(vec,it); //i = mViewerPartGroups.erase(iter); } + else ++it; } } diff --git a/indra/newview/llviewertextureanim.cpp b/indra/newview/llviewertextureanim.cpp index 2b364851a..525de0ed2 100644 --- a/indra/newview/llviewertextureanim.cpp +++ b/indra/newview/llviewertextureanim.cpp @@ -49,15 +49,9 @@ LLViewerTextureAnim::LLViewerTextureAnim(LLVOVolume* vobj) : LLTextureAnim() LLViewerTextureAnim::~LLViewerTextureAnim() { - S32 end_idx = sInstanceList.size()-1; - - if (end_idx != mInstanceIndex) - { - sInstanceList[mInstanceIndex] = sInstanceList[end_idx]; - sInstanceList[mInstanceIndex]->mInstanceIndex = mInstanceIndex; - } - - sInstanceList.pop_back(); + std::vector::iterator iter = vector_replace_with_last(sInstanceList, sInstanceList.begin() + mInstanceIndex); + if(iter != sInstanceList.end()) + (*iter)->mInstanceIndex = mInstanceIndex; } void LLViewerTextureAnim::reset() diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp index 78c8649ba..2b39ae894 100644 --- a/indra/newview/llvoavatar.cpp +++ b/indra/newview/llvoavatar.cpp @@ -6547,12 +6547,7 @@ BOOL LLVOAvatar::detachObject(LLViewerObject *viewer_object) if (attachment->isObjectAttached(viewer_object)) { - std::vector >::iterator it = std::find(mAttachedObjectsVector.begin(),mAttachedObjectsVector.end(),std::make_pair(viewer_object,attachment)); - if(it != mAttachedObjectsVector.end()) - { - (*it) = mAttachedObjectsVector.back(); - mAttachedObjectsVector.pop_back(); - } + vector_replace_with_last(mAttachedObjectsVector,std::make_pair(viewer_object,attachment)); cleanupAttachedMesh( viewer_object ); attachment->removeObject(viewer_object);