From aaf095235c027578fd2683fd2f7110019836a4d7 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Thu, 22 Oct 2020 15:25:12 -0400
Subject: [PATCH] Eliminate unnecessary copies of std::list for getChildren and
 cleanup related loops

---
 indra/newview/llcontrolavatar.cpp        | 8 ++------
 indra/newview/lldrawable.cpp             | 4 +---
 indra/newview/llfloaterobjectweights.cpp | 2 +-
 indra/newview/llspatialpartition.cpp     | 4 ++--
 indra/newview/llviewerobject.cpp         | 7 ++-----
 indra/newview/llvoavatar.cpp             | 7 ++-----
 6 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/indra/newview/llcontrolavatar.cpp b/indra/newview/llcontrolavatar.cpp
index 7e679d61088..d307d6de123 100644
--- a/indra/newview/llcontrolavatar.cpp
+++ b/indra/newview/llcontrolavatar.cpp
@@ -277,10 +277,8 @@ void LLControlAvatar::updateVolumeGeom()
 	mRootVolp->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
 
 	LLViewerObject::const_child_list_t& child_list = mRootVolp->getChildren();
-	for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-		 iter != child_list.end(); ++iter)
+	for (LLViewerObject* childp : child_list)
 	{
-		LLViewerObject* childp = *iter;
 		if (childp && childp->mDrawable.notNull())
 		{
 			childp->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
@@ -491,10 +489,8 @@ void LLControlAvatar::getAnimatedVolumes(std::vector<LLVOVolume*>& volumes)
     volumes.push_back(mRootVolp);
     
 	LLViewerObject::const_child_list_t& child_list = mRootVolp->getChildren();
-	for (LLViewerObject::const_child_list_t::const_iterator iter = child_list.begin();
-		 iter != child_list.end(); ++iter)
+	for (LLViewerObject* childp : child_list)
 	{
-		LLViewerObject* childp = *iter;
         LLVOVolume *child_volp = childp ? childp->asVolume() : nullptr;
         if (child_volp && child_volp->isAnimatedObject())
         {
diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp
index 0c8e4b582e1..7f4f4c52beb 100644
--- a/indra/newview/lldrawable.cpp
+++ b/indra/newview/lldrawable.cpp
@@ -542,10 +542,8 @@ void LLDrawable::makeActive()
 		llassert_always(mVObjp);
 		
 		LLViewerObject::const_child_list_t& child_list = mVObjp->getChildren();
-		for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-			 iter != child_list.end(); iter++)
+		for (LLViewerObject* child : child_list)
 		{
-			LLViewerObject* child = *iter;
 			LLDrawable* drawable = child->mDrawable;
 			if (drawable)
 			{
diff --git a/indra/newview/llfloaterobjectweights.cpp b/indra/newview/llfloaterobjectweights.cpp
index ed1ad4426f3..bdca3e49f07 100644
--- a/indra/newview/llfloaterobjectweights.cpp
+++ b/indra/newview/llfloaterobjectweights.cpp
@@ -43,7 +43,7 @@ bool LLCrossParcelFunctor::apply(LLViewerObject* obj)
 	mBoundingBox.addBBoxAgent(LLBBox(obj->getPositionRegion(), obj->getRotationRegion(), obj->getScale() * -0.5f, obj->getScale() * 0.5f).getAxisAligned());
 
 	// Extend the bounding box across all the children.
-	LLViewerObject::const_child_list_t children = obj->getChildren();
+	LLViewerObject::const_child_list_t& children = obj->getChildren();
 	for (LLViewerObject::const_child_list_t::const_iterator iter = children.begin();
 		 iter != children.end(); iter++)
 	{
diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index c6e2d9af77a..21210594162 100644
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -2051,7 +2051,7 @@ void renderComplexityDisplay(LLDrawable* drawablep)
 	F32 cost = (F32) voVol->getRenderCost(textures);
 
 	// add any child volumes
-	LLViewerObject::const_child_list_t children = voVol->getChildren();
+	LLViewerObject::const_child_list_t& children = voVol->getChildren();
 	for (LLViewerObject::const_child_list_t::const_iterator iter = children.begin(); iter != children.end(); ++iter)
 	{
 		LLViewerObject *child = *iter;
@@ -2116,7 +2116,7 @@ void renderComplexityDisplay(LLDrawable* drawablep)
 				pushVerts(drawablep->getFace(i), LLVertexBuffer::MAP_VERTEX);
 			}
 		}
-		LLViewerObject::const_child_list_t children = voVol->getChildren();
+		LLViewerObject::const_child_list_t& children = voVol->getChildren();
 		for (LLViewerObject::const_child_list_t::const_iterator iter = children.begin(); iter != children.end(); ++iter)
 		{
 			const LLViewerObject *child = *iter;
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index a44003ea5e1..491f7bd1b35 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -3970,12 +3970,9 @@ F32 LLViewerObject::recursiveGetScaledSurfaceArea() const
 				const LLVector3& scale = volume->getScale();
                 area += volume->getVolume()->getSurfaceArea() * llmax(llmax(scale.mV[0], scale.mV[1]), scale.mV[2]);
             }
-            LLViewerObject::const_child_list_t children = volume->getChildren();
-            for (LLViewerObject::const_child_list_t::const_iterator child_iter = children.begin();
-                 child_iter != children.end();
-                 ++child_iter)
+            const LLViewerObject::const_child_list_t& children = volume->getChildren();
+            for (LLViewerObject* child_obj : children)
             {
-                LLViewerObject* child_obj = *child_iter;
 				if(!child_obj) continue;
 
                 LLVOVolume *child = child_obj->asVolume();
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index f2440c2854e..fe122fd7cb5 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -10523,12 +10523,9 @@ void LLVOAvatar::accountRenderComplexityForObject(
                 }
 							attachment_volume_cost += volume->getRenderCost(textures);
 
-							const_child_list_t children = volume->getChildren();
-							for (const_child_list_t::const_iterator child_iter = children.begin();
-								  child_iter != children.end();
-								  ++child_iter)
+							const_child_list_t& children = volume->getChildren();
+							for (LLViewerObject* child_obj : children)
 							{
-								LLViewerObject* child_obj = *child_iter;
 								LLVOVolume *child = child_obj ? child_obj->asVolume() : nullptr;
 								if (child)
 								{
-- 
GitLab