From 7e0b94d93a1c2d4ceae02fe3b654101542d8fe06 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Fri, 23 Oct 2020 02:41:49 -0400
Subject: [PATCH] Large avatar loop cleanup part 1

---
 indra/newview/llagentwearables.cpp |  10 +-
 indra/newview/llvoavatar.cpp       | 219 ++++++++++++-----------------
 indra/newview/llvoavatarself.cpp   | 117 ++++++---------
 indra/newview/pipeline.cpp         |  13 +-
 4 files changed, 139 insertions(+), 220 deletions(-)

diff --git a/indra/newview/llagentwearables.cpp b/indra/newview/llagentwearables.cpp
index f94e656152f..5e945906a32 100644
--- a/indra/newview/llagentwearables.cpp
+++ b/indra/newview/llagentwearables.cpp
@@ -1418,15 +1418,11 @@ std::vector<LLViewerObject*> LLAgentWearables::getTempAttachments()
 	llvo_vec_t temp_attachs;
 	if (isAgentAvatarValid())
 	{
-		for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin(); iter != gAgentAvatarp->mAttachmentPoints.end();)
+		for (const auto& attach_pair : gAgentAvatarp->mAttachmentPoints)
 		{
-			LLVOAvatar::attachment_map_t::iterator curiter = iter++;
-			LLViewerJointAttachment* attachment = curiter->second;
-			for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
-				attachment_iter != attachment->mAttachedObjects.end();
-				++attachment_iter)
+			LLViewerJointAttachment* attachment = attach_pair.second;
+			for (LLViewerObject* objectp : attachment->mAttachedObjects)
 			{
-				LLViewerObject *objectp = attachment_iter->get();
 				if (objectp && objectp->isTempAttachment())
 				{
 					temp_attachs.push_back(objectp);
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 671661da14e..e96a57e1f5c 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -928,10 +928,9 @@ BOOL LLVOAvatar::areAllNearbyInstancesBaked(S32& grey_avatars)
 {
 	BOOL res = TRUE;
 	grey_avatars = 0;
-	for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
-		 iter != LLCharacter::sInstances.end(); ++iter)
+	for (LLCharacter* character : LLCharacter::sInstances)
 	{
-		LLVOAvatar* inst = (LLVOAvatar*) *iter;
+		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
 		if( inst->isDead() )
 		{
 			continue;
@@ -953,10 +952,9 @@ void LLVOAvatar::getNearbyRezzedStats(std::vector<S32>& counts)
 {
 	counts.clear();
 	counts.resize(4);
-	for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
-		 iter != LLCharacter::sInstances.end(); ++iter)
+	for (LLCharacter* character : LLCharacter::sInstances)
 	{
-		LLVOAvatar* inst = (LLVOAvatar*) *iter;
+		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
 		if (inst)
 		{
 			S32 rez_status = inst->getRezzedStatus();
@@ -980,10 +978,9 @@ void LLVOAvatar::dumpBakedStatus()
 {
 	LLVector3d camera_pos_global = gAgentCamera.getCameraPositionGlobal();
 
-	for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
-		 iter != LLCharacter::sInstances.end(); ++iter)
+	for (LLCharacter* character : LLCharacter::sInstances)
 	{
-		LLVOAvatar* inst = (LLVOAvatar*) *iter;
+		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
 		LL_INFOS() << "Avatar ";
 
 		LLNameValue* firstname = inst->getNVPair("FirstName");
@@ -1076,10 +1073,9 @@ void LLVOAvatar::destroyGL()
 //static
 void LLVOAvatar::resetImpostors()
 {
-	for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
-		 iter != LLCharacter::sInstances.end(); ++iter)
+	for (LLCharacter* character : LLCharacter::sInstances)
 	{
-		LLVOAvatar* avatar = (LLVOAvatar*) *iter;
+		LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
 		avatar->mImpostor.release();
 		avatar->mNeedsImpostorUpdate = TRUE;
 	}
@@ -1090,10 +1086,9 @@ void LLVOAvatar::deleteCachedImages(bool clearAll)
 {	
 	if (LLViewerTexLayerSet::sHasCaches)
 	{
-		for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
-			 iter != LLCharacter::sInstances.end(); ++iter)
+		for (LLCharacter* character : LLCharacter::sInstances)
 		{
-			LLVOAvatar* inst = (LLVOAvatar*) *iter;
+			LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
 			inst->deleteLayerSetCaches(clearAll);
 		}
 		LLViewerTexLayerSet::sHasCaches = FALSE;
@@ -1347,19 +1342,18 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
 	//stretch bounding box by joint positions. Doing this for
 	//control avs, where the polymeshes aren't maintained or
 	//displayed, can give inaccurate boxes due to joints stuck at (0,0,0).
-    if ((box_detail>=1) && !isControlAvatar())
+    if ((box_detail >= 1) && !isControlAvatar())
     {
-	for (polymesh_map_t::iterator i = mPolyMeshes.begin(); i != mPolyMeshes.end(); ++i)
-	{
-		LLPolyMesh* mesh = i->second;
-		for (S32 joint_num = 0; joint_num < mesh->mJointRenderData.size(); joint_num++)
-		{
-			LLVector4a trans;
-			trans.load3( mesh->mJointRenderData[joint_num]->mWorldMatrix->getTranslation().mV);
-			update_min_max(newMin, newMax, trans);
-		}
-	}
-
+        for (const auto &polymesh_pair : mPolyMeshes)
+        {
+            LLPolyMesh *mesh = polymesh_pair.second;
+            for (S32 joint_num = 0; joint_num < mesh->mJointRenderData.size(); joint_num++)
+            {
+                LLVector4a trans;
+                trans.load3(mesh->mJointRenderData[joint_num]->mWorldMatrix->getTranslation().mV);
+                update_min_max(newMin, newMax, trans);
+            }
+        }
     }
 
 	// Pad bounding box for starting joint, plus polymesh if
@@ -1370,38 +1364,36 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
 	newMax.add(padding);
 
 
-	//stretch bounding box by static attachments
+	// stretch bounding box by static attachments
     if (box_detail >= 2)
     {
         float max_attachment_span = get_default_max_prim_scale() * 5.0f;
-	
-	for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end();
-		 ++iter)
-	{
-		LLViewerJointAttachment* attachment = iter->second;
 
-		if (attachment->getValid())
-		{
-			for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-			{
-                // Don't we need to look at children of attached_object as well?
-				if (attached_object && !attached_object->isHUDAttachment())
-				{
-                        const LLVOVolume *vol = attached_object->asVolume();
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            LLViewerJointAttachment* attachment = attach_pair.second;
+
+            if (attachment->getValid())
+            {
+                for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+                {
+                    // Don't we need to look at children of attached_object as well?
+                    if (attached_object && !attached_object->isHUDAttachment())
+                    {
+                        const LLVOVolume* vol = attached_object->asVolume();
                         if (vol && vol->isAnimatedObject())
                         {
-                            // Animated objects already have a bounding box in their control av, use that. 
+                            // Animated objects already have a bounding box in their control av, use that.
                             // Could lag by a frame if there's no guarantee on order of processing for avatars.
-                            const LLControlAvatar *cav = vol->getControlAvatar();
+                            const LLControlAvatar* cav = vol->getControlAvatar();
                             if (cav)
                             {
                                 LLVector4a cav_min;
                                 cav_min.load3(cav->mLastAnimExtents[0].mV);
                                 LLVector4a cav_max;
                                 cav_max.load3(cav->mLastAnimExtents[1].mV);
-                                update_min_max(newMin,newMax,cav_min);
-                                update_min_max(newMin,newMax,cav_max);
+                                update_min_max(newMin, newMax, cav_min);
+                                update_min_max(newMin, newMax, cav_max);
                                 continue;
                             }
                         }
@@ -1409,33 +1401,33 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
                         {
                             continue;
                         }
-					LLDrawable* drawable = attached_object->mDrawable;
-					if (drawable && !drawable->isState(LLDrawable::RIGGED))
-					{
-						const LLSpatialBridge* bridge = drawable->getSpatialBridge();
-						if (bridge)
-						{
-							const LLVector4a* ext = bridge->getSpatialExtents();
-							LLVector4a distance;
-							distance.setSub(ext[1], ext[0]);
-							LLVector4a max_span(max_attachment_span);
+                        LLDrawable* drawable = attached_object->mDrawable;
+                        if (drawable && !drawable->isState(LLDrawable::RIGGED))
+                        {
+                            const LLSpatialBridge* bridge = drawable->getSpatialBridge();
+                            if (bridge)
+                            {
+                                const LLVector4a* ext = bridge->getSpatialExtents();
+                                LLVector4a        distance;
+                                distance.setSub(ext[1], ext[0]);
+                                LLVector4a max_span(max_attachment_span);
 
-							S32 lt = distance.lessThan(max_span).getGatheredBits() & 0x7;
-						
-							// Only add the prim to spatial extents calculations if it isn't a megaprim.
-							// max_attachment_span calculated at the start of the function 
-							// (currently 5 times our max prim size) 
-							if (lt == 0x7)
-							{
-								update_min_max(newMin,newMax,ext[0]);
-								update_min_max(newMin,newMax,ext[1]);
-							}
-						}
-					}
-				}
-			}
-		}
-	}
+                                S32 lt = distance.lessThan(max_span).getGatheredBits() & 0x7;
+
+                                // Only add the prim to spatial extents calculations if it isn't a megaprim.
+                                // max_attachment_span calculated at the start of the function
+                                // (currently 5 times our max prim size)
+                                if (lt == 0x7)
+                                {
+                                    update_min_max(newMin, newMax, ext[0]);
+                                    update_min_max(newMin, newMax, ext[1]);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
     }
 
     // Stretch bounding box by rigged mesh joint boxes
@@ -1585,9 +1577,6 @@ void LLVOAvatar::renderBones(const std::string &selected_joint)
 {
     LLGLEnable blend(GL_BLEND);
 
-	avatar_joint_list_t::iterator iter = mSkeleton.begin();
-    avatar_joint_list_t::iterator end = mSkeleton.end();
-
     // For selected joints
     static LLVector3 SELECTED_COLOR_OCCLUDED(1.0f, 1.0f, 0.0f);
     static LLVector3 SELECTED_COLOR_VISIBLE(0.5f, 0.5f, 0.5f);
@@ -1603,9 +1592,8 @@ void LLVOAvatar::renderBones(const std::string &selected_joint)
     
     static F32 SPHERE_SCALEF = 0.001f;
 
-	for (; iter != end; ++iter)
+	for (LLJoint* jointp : mSkeleton)
 	{
-		LLJoint* jointp = *iter;
 		if (!jointp)
 		{
 			continue;
@@ -1811,18 +1799,12 @@ BOOL LLVOAvatar::lineSegmentIntersect(const LLVector4a& start, const LLVector4a&
 
 		if (isSelf())
 		{
-			for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-			 iter != mAttachmentPoints.end();
-			 ++iter)
+			for (const auto& attach_pair : mAttachmentPoints)
 			{
-				LLViewerJointAttachment* attachment = iter->second;
+				LLViewerJointAttachment* attachment = attach_pair.second;
 
-				for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
-					 attachment_iter != attachment->mAttachedObjects.end();
-					 ++attachment_iter)
+				for (LLViewerObject* attached_object : attachment->mAttachedObjects)
 				{
-					LLViewerObject* attached_object = attachment_iter->get();
-					
 					if (attached_object && !attached_object->isDead() && attachment->getValid())
 					{
 						LLDrawable* drawable = attached_object->mDrawable;
@@ -1875,18 +1857,12 @@ LLViewerObject* LLVOAvatar::lineSegmentIntersectRiggedAttachments(const LLVector
 		LLVector4a local_end = end;
 		LLVector4a local_intersection;
 
-		for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-			iter != mAttachmentPoints.end();
-			++iter)
+		for (const auto& attach_pair : mAttachmentPoints)
 		{
-			LLViewerJointAttachment* attachment = iter->second;
+			LLViewerJointAttachment* attachment = attach_pair.second;
 
-			for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
-					attachment_iter != attachment->mAttachedObjects.end();
-					++attachment_iter)
+			for (LLViewerObject* attached_object : attachment->mAttachedObjects)
 			{
-				LLViewerObject* attached_object = attachment_iter->get();
-					
 				if (attached_object->lineSegmentIntersect(start, local_end, face, pick_transparent, pick_rigged, face_hit, &local_intersection, tex_coord, normal, tangent))
 				{
 					local_end = local_intersection;
@@ -1994,11 +1970,9 @@ void LLVOAvatar::resetVisualParams()
 	// Skeletal params
 	{
 		LLAvatarXmlInfo::skeletal_distortion_info_list_t::iterator iter;
-		for (iter = sAvatarXmlInfo->mSkeletalDistortionInfoList.begin();
-			 iter != sAvatarXmlInfo->mSkeletalDistortionInfoList.end(); 
-			 ++iter)
+		for (LLViewerVisualParamInfo* vparam : sAvatarXmlInfo->mSkeletalDistortionInfoList)
 		{
-			LLPolySkeletalDistortionInfo *info = (LLPolySkeletalDistortionInfo*)*iter;
+			LLPolySkeletalDistortionInfo *info = static_cast<LLPolySkeletalDistortionInfo*>(vparam);
 			LLPolySkeletalDistortion *param = static_cast<LLPolySkeletalDistortion*>(getVisualParam(info->getID()));
             *param = LLPolySkeletalDistortion(this);
             llassert(param);
@@ -2010,13 +1984,10 @@ void LLVOAvatar::resetVisualParams()
 	}
 
 	// Driver parameters
-	for (LLAvatarXmlInfo::driver_info_list_t::iterator iter = sAvatarXmlInfo->mDriverInfoList.begin();
-		 iter != sAvatarXmlInfo->mDriverInfoList.end(); 
-		 ++iter)
+	for (LLDriverParamInfo* info : sAvatarXmlInfo->mDriverInfoList)
 	{
-		LLDriverParamInfo *info = *iter;
         LLDriverParam *param = static_cast<LLDriverParam*>(getVisualParam(info->getID()));
-        LLDriverParam::entry_list_t driven_list = param->getDrivenList();
+        LLDriverParam::entry_list_t& driven_list = param->getDrivenList();
         *param = LLDriverParam(this);
         llassert(param);
         if (!param->setInfo(info))
@@ -2130,11 +2101,8 @@ void LLVOAvatar::releaseMeshData()
 	}
 
 	// cleanup mesh data
-	for (avatar_joint_list_t::iterator iter = mMeshLOD.begin();
-		 iter != mMeshLOD.end(); 
-		 ++iter)
+	for (LLAvatarJoint* joint : mMeshLOD)
 	{
-		LLAvatarJoint* joint = (*iter);
 		joint->setValid(FALSE, TRUE);
 	}
 
@@ -2156,11 +2124,9 @@ void LLVOAvatar::releaseMeshData()
 		}
 	}
 	
-	for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end();
-		 ++iter)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		LLViewerJointAttachment* attachment = iter->second;
+		LLViewerJointAttachment* attachment = attach_pair.second;
 		if (!attachment->getIsHUDAttachment())
 		{
 			attachment->setAttachmentVisibility(FALSE);
@@ -2185,11 +2151,9 @@ void LLVOAvatar::restoreMeshData()
 	mMeshValid = TRUE;
 	updateJointLODs();
 
-	for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end();
-		 ++iter)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		LLViewerJointAttachment* attachment = iter->second;
+		LLViewerJointAttachment* attachment = attach_pair.second;
 		if (!attachment->getIsHUDAttachment())
 		{
 			attachment->setAttachmentVisibility(TRUE);
@@ -2439,19 +2403,19 @@ static LLTrace::BlockTimerStatHandle FTM_JOINT_UPDATE("Update Joints");
 void LLVOAvatar::dumpAnimationState()
 {
 	LL_INFOS() << "==============================================" << LL_ENDL;
-	for (LLVOAvatar::AnimIterator it = mSignaledAnimations.begin(); it != mSignaledAnimations.end(); ++it)
+	for (const auto& sig_anim_pair : mSignaledAnimations)
 	{
-		LLUUID id = it->first;
-		std::string playtag = "";
+		const LLUUID& id = sig_anim_pair.first;
+		std::string playtag;
 		if (mPlayingAnimations.find(id) != mPlayingAnimations.end())
 		{
 			playtag = "*";
 		}
 		LL_INFOS() << gAnimLibrary.animationName(id) << playtag << LL_ENDL;
 	}
-	for (LLVOAvatar::AnimIterator it = mPlayingAnimations.begin(); it != mPlayingAnimations.end(); ++it)
+	for (const auto& playing_anim_pair : mPlayingAnimations)
 	{
-		LLUUID id = it->first;
+		const LLUUID& id = playing_anim_pair.first;
 		bool is_signaled = mSignaledAnimations.find(id) != mSignaledAnimations.end();
 		if (!is_signaled)
 		{
@@ -3372,7 +3336,7 @@ void LLVOAvatar::idleUpdateNameTagText(BOOL new_name)
 		mNameText->setTextAlignment(LLHUDNameTag::ALIGN_TEXT_LEFT);
 		mNameText->setFadeDistance(CHAT_NORMAL_RADIUS * 2.f, 5.f);
 
-		std::deque<LLChat>::iterator chat_iter = mChats.begin();
+		std::deque<LLChat>::iterator chat_iter = mChats.begin(), chat_iter_end = mChats.end();
 		mNameText->clearString();
 
 		static LLUIColor user_chat_color = LLUIColorTable::instance().getColor("UserChatColor");
@@ -3386,7 +3350,7 @@ void LLVOAvatar::idleUpdateNameTagText(BOOL new_name)
 			++chat_iter;
 		}
 
-		for(; chat_iter != mChats.end(); ++chat_iter)
+		for(; chat_iter != chat_iter_end; ++chat_iter)
 		{
 			F32 chat_fade_amt = llclamp((F32)((LLFrameTimer::getElapsedSeconds() - chat_iter->mTime) / CHAT_FADE_TIME), 0.f, 4.f);
 			LLFontGL::StyleFlags style;
@@ -3487,10 +3451,9 @@ void LLVOAvatar::invalidateNameTag(const LLUUID& agent_id)
 //static
 void LLVOAvatar::invalidateNameTags()
 {
-	std::vector<LLCharacter*>::iterator it = LLCharacter::sInstances.begin();
-	for ( ; it != LLCharacter::sInstances.end(); ++it)
+	for (LLCharacter* character : LLCharacter::sInstances)
 	{
-		LLVOAvatar* avatar = static_cast<LLVOAvatar*>(*it);
+		LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
 		if (!avatar) continue;
 		if (avatar->isDead()) continue;
 
@@ -3804,10 +3767,8 @@ LLViewerInventoryItem* recursiveGetObjectInventoryItem(LLViewerObject *vobj, LLU
     if (!item)
     {
         LLViewerObject::const_child_list_t& children = vobj->getChildren();
-        for (LLViewerObject::const_child_list_t::const_iterator it = children.begin();
-             it != children.end(); ++it)
+        for (LLViewerObject* childp : children)
         {
-            LLViewerObject *childp = *it;
             item = getObjectInventoryItem(childp, asset_id);
             if (item)
 	{
diff --git a/indra/newview/llvoavatarself.cpp b/indra/newview/llvoavatarself.cpp
index 11ed18b8599..d3b11ae7a9b 100644
--- a/indra/newview/llvoavatarself.cpp
+++ b/indra/newview/llvoavatarself.cpp
@@ -445,11 +445,9 @@ BOOL LLVOAvatarSelf::buildMenus()
 		}
 		else
 		{
-			for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-				 iter != mAttachmentPoints.end();
-				 ++iter)
+			for (const auto& attach_pair : mAttachmentPoints)
 			{
-				LLViewerJointAttachment* attachment = iter->second;
+				const LLViewerJointAttachment* attachment = attach_pair.second;
 				if (attachment && attachment->getGroup() == i)
 				{
 					LLMenuItemCallGL::Params item_params;
@@ -465,10 +463,10 @@ BOOL LLVOAvatarSelf::buildMenus()
 					}
 					item_params.name =(item_params.label );
 					item_params.on_click.function_name = "Object.AttachToAvatar";
-					item_params.on_click.parameter = iter->first;
+					item_params.on_click.parameter = attach_pair.first;
 					// [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
 					item_params.on_enable.function_name = "Object.EnableWear";
-					item_params.on_enable.parameter = iter->first;
+					item_params.on_enable.parameter = attach_pair.first;
 					LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
 
 					gAttachPieMenu->addChild(item);
@@ -485,11 +483,9 @@ BOOL LLVOAvatarSelf::buildMenus()
 		}
 		else
 		{
-			for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-				 iter != mAttachmentPoints.end();
-				 ++iter)
+			for (const auto& attach_pair : mAttachmentPoints)
 			{
-				LLViewerJointAttachment* attachment = iter->second;
+				const LLViewerJointAttachment* attachment = attach_pair.second;
 				if (attachment && attachment->getGroup() == i)
 				{
 					LLMenuItemCallGL::Params item_params;
@@ -504,9 +500,9 @@ BOOL LLVOAvatarSelf::buildMenus()
 					}
 					item_params.name =(item_params.label );
 					item_params.on_click.function_name = "Attachment.DetachFromPoint";
-					item_params.on_click.parameter = iter->first;
+					item_params.on_click.parameter = attach_pair.first;
 					item_params.on_enable.function_name = "Attachment.PointFilled";
-					item_params.on_enable.parameter = iter->first;
+					item_params.on_enable.parameter = attach_pair.first;
 					LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
 
 					gDetachPieMenu->addChild(item);
@@ -518,11 +514,9 @@ BOOL LLVOAvatarSelf::buildMenus()
 	}
 
 	// add screen attachments
-	for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end();
-		 ++iter)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		LLViewerJointAttachment* attachment = iter->second;
+		const LLViewerJointAttachment* attachment = attach_pair.second;
 		if (attachment->getGroup() == 9)
 		{
 			LLMenuItemCallGL::Params item_params;
@@ -537,17 +531,17 @@ BOOL LLVOAvatarSelf::buildMenus()
 			}
 			item_params.name =(item_params.label );
 			item_params.on_click.function_name = "Object.AttachToAvatar";
-			item_params.on_click.parameter = iter->first;
+			item_params.on_click.parameter = attach_pair.first;
 			// [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
 			item_params.on_enable.function_name = "Object.EnableWear";
-			item_params.on_enable.parameter = iter->first;
+			item_params.on_enable.parameter = attach_pair.first;
 			LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
 			gAttachScreenPieMenu->addChild(item);
 
 			item_params.on_click.function_name = "Attachment.DetachFromPoint";
-			item_params.on_click.parameter = iter->first;
+			item_params.on_click.parameter = attach_pair.first;
 			item_params.on_enable.function_name = "Attachment.PointFilled";
-			item_params.on_enable.parameter = iter->first;
+			item_params.on_enable.parameter = attach_pair.first;
 			item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
 			gDetachScreenPieMenu->addChild(item);
 		}
@@ -560,11 +554,9 @@ BOOL LLVOAvatarSelf::buildMenus()
 		{
 			break;
 		}
-		for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-			 iter != mAttachmentPoints.end();
-			 ++iter)
+		for (const auto& attach_pair : mAttachmentPoints)
 		{
-			LLViewerJointAttachment* attachment = iter->second;
+			const LLViewerJointAttachment* attachment = attach_pair.second;
 			if (attachment->getIsHUDAttachment() != (pass == 1))
 			{
 				continue;
@@ -581,10 +573,10 @@ BOOL LLVOAvatarSelf::buildMenus()
 			}
 			item_params.name =(item_params.label );
 			item_params.on_click.function_name = "Object.AttachToAvatar";
-			item_params.on_click.parameter = iter->first;
+			item_params.on_click.parameter = attach_pair.first;
 			// [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
 			item_params.on_enable.function_name = "Object.EnableWear";
-			item_params.on_enable.parameter = iter->first;
+			item_params.on_enable.parameter = attach_pair.first;
 			//* TODO: Skinning:
 			//LLSD params;
 			//params["index"] = iter->first;
@@ -595,9 +587,9 @@ BOOL LLVOAvatarSelf::buildMenus()
 			gAttachSubMenu->addChild(item);
 
 			item_params.on_click.function_name = "Attachment.DetachFromPoint";
-			item_params.on_click.parameter = iter->first;
+			item_params.on_click.parameter = attach_pair.first;
 			item_params.on_enable.function_name = "Attachment.PointFilled";
-			item_params.on_enable.parameter = iter->first;
+			item_params.on_enable.parameter = attach_pair.first;
 			//* TODO: Skinning: item->addEventHandler("on_enable", LLMenuItemCallGL::MenuCallback().function_name("Attachment.Label").parameter(params));
 
 			item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
@@ -622,16 +614,14 @@ BOOL LLVOAvatarSelf::buildMenus()
 		std::multimap<S32, S32> attachment_pie_menu_map;
 
 		// gather up all attachment points assigned to this group, and throw into map sorted by pie slice number
-		for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-			 iter != mAttachmentPoints.end();
-			 ++iter)
+		for (const auto& attach_pair : mAttachmentPoints)
 		{
-			LLViewerJointAttachment* attachment = iter->second;
+			LLViewerJointAttachment* attachment = attach_pair.second;
 			if(attachment && attachment->getGroup() == group)
 			{
 				// use multimap to provide a partial order off of the pie slice key
 				S32 pie_index = attachment->getPieSlice();
-				attachment_pie_menu_map.insert(std::make_pair(pie_index, iter->first));
+				attachment_pie_menu_map.insert(std::make_pair(pie_index, attach_pair.first));
 			}
 		}
 
@@ -1066,11 +1056,9 @@ void LLVOAvatarSelf::restoreMeshData()
 //-----------------------------------------------------------------------------
 void LLVOAvatarSelf::updateAttachmentVisibility(U32 camera_mode)
 {
-	for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end();
-		 ++iter)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		LLViewerJointAttachment* attachment = iter->second;
+		LLViewerJointAttachment* attachment = attach_pair.second;
 		if (attachment->getIsHUDAttachment())
 		{
 			attachment->setAttachmentVisibility(TRUE);
@@ -1127,11 +1115,8 @@ void LLVOAvatarSelf::wearableUpdated(LLWearableType::EType type)
 
 		if (baked_dict)
 		{
-			for (LLAvatarAppearanceDefines::wearables_vec_t::const_iterator type_iter = baked_dict->mWearables.begin();
-				type_iter != baked_dict->mWearables.end();
-				 ++type_iter)
+			for (const LLWearableType::EType comp_type : baked_dict->mWearables)
 			{
-				const LLWearableType::EType comp_type = *type_iter;
 				if (comp_type == type)
 				{
 					LLViewerTexLayerSet *layerset = getLayerSet(index);
@@ -1153,11 +1138,9 @@ void LLVOAvatarSelf::wearableUpdated(LLWearableType::EType type)
 BOOL LLVOAvatarSelf::isWearingAttachment(const LLUUID& inv_item_id) const
 {
 	const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
-	for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end();
-		 ++iter)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		const LLViewerJointAttachment* attachment = iter->second;
+		const LLViewerJointAttachment* attachment = attach_pair.second;
 		if (attachment->getAttachedObject(base_inv_item_id))
 		{
 			return TRUE;
@@ -1172,11 +1155,9 @@ BOOL LLVOAvatarSelf::isWearingAttachment(const LLUUID& inv_item_id) const
 LLViewerObject* LLVOAvatarSelf::getWornAttachment(const LLUUID& inv_item_id)
 {
 	const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
-	for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end();
-		 ++iter)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		LLViewerJointAttachment* attachment = iter->second;
+		LLViewerJointAttachment* attachment = attach_pair.second;
  		if (LLViewerObject *attached_object = attachment->getAttachedObject(base_inv_item_id))
 		{
 			return attached_object;
@@ -1197,9 +1178,9 @@ boost::signals2::connection LLVOAvatarSelf::setAttachmentCallback(const attachme
 LLViewerJointAttachment* LLVOAvatarSelf::getWornAttachmentPoint(const LLUUID& idItem) const
 {
 	const LLUUID& idItemBase = gInventory.getLinkedItemID(idItem);
-	for (attachment_map_t::const_iterator itAttachPt = mAttachmentPoints.begin(); itAttachPt != mAttachmentPoints.end(); ++itAttachPt)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		LLViewerJointAttachment* pAttachPt = itAttachPt->second;
+		LLViewerJointAttachment* pAttachPt = attach_pair.second;
  		if (pAttachPt->getAttachedObject(idItemBase))
 			return pAttachPt;
 	}
@@ -1220,11 +1201,9 @@ bool LLVOAvatarSelf::getAttachedPointName(const LLUUID& inv_item_id, std::string
 		name = "ATTACHMENT_MISSING_BASE_ITEM";
 		return false;
 	}
-	for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(); 
-		 iter != mAttachmentPoints.end(); 
-		 ++iter)
+	for (const auto& attach_pair : mAttachmentPoints)
 	{
-		const LLViewerJointAttachment* attachment = iter->second;
+		const LLViewerJointAttachment* attachment = attach_pair.second;
 		if (attachment->getAttachedObject(base_inv_item_id))
 		{
 			name = attachment->getName();
@@ -1285,9 +1264,9 @@ BOOL LLVOAvatarSelf::detachObject(LLViewerObject *viewer_object)
 	// NOTE: RLVa event handlers should be invoked *before* LLVOAvatar::detachObject() calls LLViewerJointAttachment::removeObject()
 	if (rlv_handler_t::isEnabled())
 	{
-		for (attachment_map_t::const_iterator itAttachPt = mAttachmentPoints.begin(); itAttachPt != mAttachmentPoints.end(); ++itAttachPt)
+		for (const auto& attach_pair : mAttachmentPoints)
 		{
-			const LLViewerJointAttachment* pAttachPt = itAttachPt->second;
+			const LLViewerJointAttachment* pAttachPt = attach_pair.second;
 			if (pAttachPt->isObjectAttached(viewer_object))
 			{
 				RlvAttachmentLockWatchdog::instance().onDetach(viewer_object, pAttachPt);
@@ -1309,11 +1288,8 @@ BOOL LLVOAvatarSelf::detachObject(LLViewerObject *viewer_object)
 		LLFollowCamMgr::getInstance()->setCameraActive(viewer_object->getID(), FALSE);
 		
 		LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
-		for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-			 iter != child_list.end(); 
-			 ++iter)
+		for (LLViewerObject* child_objectp : child_list)
 		{
-			LLViewerObject* child_objectp = *iter;
 			// the simulator should automatically handle
 			// permissions revocation
 			
@@ -1501,11 +1477,8 @@ BOOL LLVOAvatarSelf::isLocalTextureDataAvailable(const LLViewerTexLayerSet* laye
 		{
 			BOOL ret = true;
 			const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
-			for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
-				 local_tex_iter != baked_dict->mLocalTextures.end();
-				 ++local_tex_iter)
+			for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
 			{
-				const ETextureIndex tex_index = *local_tex_iter;
 				const LLWearableType::EType wearable_type = LLAvatarAppearanceDictionary::getTEWearableType(tex_index);
 				const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
 				for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
@@ -1538,16 +1511,13 @@ BOOL LLVOAvatarSelf::isLocalTextureDataFinal(const LLViewerTexLayerSet* layerset
 		if (layerset == mBakedTextureDatas[i].mTexLayerSet)
 		{
 			const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = avApprDict.getBakedTexture((EBakedTextureIndex)i);
-			for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
-				 local_tex_iter != baked_dict->mLocalTextures.end();
-				 ++local_tex_iter)
+			for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
 			{
-				const ETextureIndex tex_index = *local_tex_iter;
 				const LLWearableType::EType wearable_type = LLAvatarAppearanceDictionary::getTEWearableType(tex_index);
 				const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
 				for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
 				{
-					S32 local_discard_level = getLocalDiscardLevel(*local_tex_iter, wearable_index);
+					S32 local_discard_level = getLocalDiscardLevel(tex_index, wearable_index);
 					if ((local_discard_level > (S32)(desired_tex_discard_level)) ||
 						(local_discard_level < 0 ))
 					{
@@ -1572,16 +1542,13 @@ BOOL LLVOAvatarSelf::isAllLocalTextureDataFinal() const
 	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
 	{
 		const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = avApprDict.getBakedTexture((EBakedTextureIndex)i);
-		for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
-			 local_tex_iter != baked_dict->mLocalTextures.end();
-			 ++local_tex_iter)
+		for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
 		{
-			const ETextureIndex tex_index = *local_tex_iter;
 			const LLWearableType::EType wearable_type = LLAvatarAppearanceDictionary::getTEWearableType(tex_index);
 			const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
 			for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
 			{
-				S32 local_discard_level = getLocalDiscardLevel(*local_tex_iter, wearable_index);
+				S32 local_discard_level = getLocalDiscardLevel(tex_index, wearable_index);
 				if ((local_discard_level > (S32)(desired_tex_discard_level)) ||
 					(local_discard_level < 0 ))
 				{
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 34d47006c9f..e5d020965b7 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -10875,17 +10875,12 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 		markVisible(avatar->mDrawable, viewer_camera);
 		LLVOAvatar::sUseImpostors = false; // @TODO ???
 
-		LLVOAvatar::attachment_map_t::iterator iter;
-		for (iter = avatar->mAttachmentPoints.begin();
-			iter != avatar->mAttachmentPoints.end();
-			++iter)
+		for (const auto& attach_pair : avatar->mAttachmentPoints)
 		{
-			LLViewerJointAttachment *attachment = iter->second;
-			for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
-				 attachment_iter != attachment->mAttachedObjects.end();
-				 ++attachment_iter)
+			LLViewerJointAttachment *attachment = attach_pair.second;
+			for (LLViewerObject* attached_object : attachment->mAttachedObjects)
 			{
-				if (LLViewerObject* attached_object = attachment_iter->get())
+				if (attached_object)
 				{
 					markVisible(attached_object->mDrawable->getSpatialBridge(), viewer_camera);
 				}
-- 
GitLab