Utilize vector_replace_with_last

This commit is contained in:
Shyotl
2014-07-05 19:29:10 -05:00
parent e2fa94e2c3
commit 4697216c5e
7 changed files with 28 additions and 71 deletions

View File

@@ -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() ;
}

View File

@@ -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<LLFace*>::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)

View File

@@ -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<LLVolumeImplFlexible*>::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

View File

@@ -1459,15 +1459,10 @@ void LLViewerObjectList::removeFromActiveList(LLViewerObject* objectp)
objectp->setListIndex(-1);
S32 last_index = mActiveObjects.size()-1;
std::vector<LLPointer<LLViewerObject> >::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();
}
}

View File

@@ -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;i<vec.size();++i)
for (group_list_t::iterator it = vec.begin();it!=vec.end();)
{
if (vec[i]->getRegion() == 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;
}
}

View File

@@ -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<LLViewerTextureAnim*>::iterator iter = vector_replace_with_last(sInstanceList, sInstanceList.begin() + mInstanceIndex);
if(iter != sInstanceList.end())
(*iter)->mInstanceIndex = mInstanceIndex;
}
void LLViewerTextureAnim::reset()

View File

@@ -6547,12 +6547,7 @@ BOOL LLVOAvatar::detachObject(LLViewerObject *viewer_object)
if (attachment->isObjectAttached(viewer_object))
{
std::vector<std::pair<LLViewerObject*,LLViewerJointAttachment*> >::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);