From 6553f01462744dbde02bb1e303ce54b025e6a79f Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Thu, 22 Oct 2020 17:01:09 -0400
Subject: [PATCH] Yet more loop cleanup

---
 indra/newview/altoolalign.cpp        | 18 +++++--------
 indra/newview/llmaniprotate.cpp      |  4 +--
 indra/newview/llmanipscale.cpp       | 16 ++++++------
 indra/newview/llpanelface.cpp        |  4 +--
 indra/newview/llviewerfoldertype.cpp | 16 +++++-------
 indra/newview/llviewerinventory.cpp  | 10 +++----
 indra/newview/llviewermenu.cpp       | 39 ++++++++--------------------
 indra/newview/llvoavatar.cpp         | 11 +++-----
 8 files changed, 40 insertions(+), 78 deletions(-)

diff --git a/indra/newview/altoolalign.cpp b/indra/newview/altoolalign.cpp
index d62221d3720..6ab447ac5da 100644
--- a/indra/newview/altoolalign.cpp
+++ b/indra/newview/altoolalign.cpp
@@ -231,18 +231,16 @@ void render_cone_bbox(LLBBox bbox)
 // should this be cached in the selection manager?  yes.
 LLBBox get_selection_axis_aligned_bbox()
 {
-	LLBBox selection_bbox = LLSelectMgr::getInstance()->getBBoxOfSelection();
+	auto& select_mgr = LLSelectMgr::instance();
+	LLBBox selection_bbox = select_mgr.getBBoxOfSelection();
 	LLVector3 position = selection_bbox.getPositionAgent();
 
 	LLBBox axis_aligned_bbox = LLBBox(position, LLQuaternion(), LLVector3(), LLVector3());
 	axis_aligned_bbox.addPointLocal(LLVector3());
 
 	// cycle over the nodes in selection
-	for (LLObjectSelection::iterator selection_iter = LLSelectMgr::getInstance()->getSelection()->begin();
-		selection_iter != LLSelectMgr::getInstance()->getSelection()->end();
-		++selection_iter)
+	for (LLSelectNode* select_node : select_mgr.getSelection()->begin_end())
 	{
-		LLSelectNode *select_node = *selection_iter;
 		if (select_node)
 		{
 			LLViewerObject* object = select_node->getObject();
@@ -425,17 +423,15 @@ class BBoxCompare
 void ALToolAlign::align()
 {
 	// no linkset parts, please
-	LLSelectMgr::getInstance()->promoteSelectionToRoot();
+	auto& select_mgr = LLSelectMgr::instance();
+	select_mgr.promoteSelectionToRoot();
 
 	std::vector<LLPointer<LLViewerObject> > objects;
 	std::map<LLPointer<LLViewerObject>, LLBBox > original_bboxes;
 
 	// cycle over the nodes in selection and collect them into an array
-	for (LLObjectSelection::root_iterator selection_iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
-		 selection_iter != LLSelectMgr::getInstance()->getSelection()->root_end();
-		 ++selection_iter)
+	for (LLSelectNode* select_node : select_mgr.getSelection()->root_begin_end())
 	{
-		LLSelectNode *select_node = *selection_iter;
 		if (select_node)
 		{
 			LLViewerObject* object = select_node->getObject();
@@ -564,5 +560,5 @@ void ALToolAlign::align()
 		object->setPosition(new_position);
 	}
 
-	LLSelectMgr::getInstance()->sendMultipleUpdate(UPD_POSITION);
+	select_mgr.sendMultipleUpdate(UPD_POSITION);
 }
diff --git a/indra/newview/llmaniprotate.cpp b/indra/newview/llmaniprotate.cpp
index 89abcbe8139..c39f57df27e 100644
--- a/indra/newview/llmaniprotate.cpp
+++ b/indra/newview/llmaniprotate.cpp
@@ -730,10 +730,8 @@ void LLManipRotate::drag( S32 x, S32 y )
 	}
 
 	// store changes to override updates
-	for (LLObjectSelection::iterator iter = LLSelectMgr::getInstance()->getSelection()->begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->end(); iter++)
+	for (LLSelectNode* selectNode : LLSelectMgr::getInstance()->getSelection()->begin_end())
 	{
-		LLSelectNode* selectNode = *iter;
 		LLViewerObject*cur = selectNode->getObject();
 		LLViewerObject *root_object = (cur == NULL) ? NULL : cur->getRootEdit();
 		if( cur->permModify() && cur->permMove() && !cur->isPermanentEnforced() &&
diff --git a/indra/newview/llmanipscale.cpp b/indra/newview/llmanipscale.cpp
index b99176edfcc..6ae12a1249b 100644
--- a/indra/newview/llmanipscale.cpp
+++ b/indra/newview/llmanipscale.cpp
@@ -391,16 +391,17 @@ BOOL LLManipScale::handleMouseUp(S32 x, S32 y, MASK mask)
 		}
 
 		//send texture update
-		LLSelectMgr::getInstance()->adjustTexturesByScale(TRUE, getStretchTextures());
+		auto& select_mgr = LLSelectMgr::instance();
+		select_mgr.adjustTexturesByScale(TRUE, getStretchTextures());
 
-		LLSelectMgr::getInstance()->enableSilhouette(TRUE);
+		select_mgr.enableSilhouette(TRUE);
 		mManipPart = LL_NO_PART;
 
 		// Might have missed last update due to UPDATE_DELAY timing
-		LLSelectMgr::getInstance()->sendMultipleUpdate( mLastUpdateFlags );
+		select_mgr.sendMultipleUpdate( mLastUpdateFlags );
 
 		//gAgent.setObjectTracking(gSavedSettings.getBOOL("TrackFocusObject"));
-		LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+		select_mgr.saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
 	}
 	return LLManip::handleMouseUp(x, y, mask);
 }
@@ -810,10 +811,9 @@ void LLManipScale::drag( S32 x, S32 y )
 	}
 
 	// store changes to override updates
-	for (LLObjectSelection::iterator iter = LLSelectMgr::getInstance()->getSelection()->begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->end(); iter++)
+	auto& select_mgr = LLSelectMgr::instance();
+	for (LLSelectNode* selectNode : select_mgr.getSelection()->begin_end())
 	{
-		LLSelectNode* selectNode = *iter;
 		LLViewerObject*cur = selectNode->getObject();
 		LLViewerObject *root_object = (cur == NULL) ? NULL : cur->getRootEdit();
 		if( cur->permModify() && cur->permMove() && !cur->isPermanentEnforced() &&
@@ -825,7 +825,7 @@ void LLManipScale::drag( S32 x, S32 y )
 		}
 	}
 
-	LLSelectMgr::getInstance()->updateSelectionCenter();
+	select_mgr.updateSelectionCenter();
 	gAgentCamera.clearFocusObject();
 }
 
diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp
index ea8a2725a49..5559d72d2b4 100644
--- a/indra/newview/llpanelface.cpp
+++ b/indra/newview/llpanelface.cpp
@@ -1913,10 +1913,8 @@ void LLPanelFace::onCommitGlow(LLUICtrl* ctrl, void* userdata)
 BOOL LLPanelFace::onDragTexture(LLUICtrl*, LLInventoryItem* item)
 {
 	BOOL accept = TRUE;
-	for (LLObjectSelection::root_iterator iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->root_end(); iter++)
+	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
 	{
-		LLSelectNode* node = *iter;
 		LLViewerObject* obj = node->getObject();
 		if(!LLToolDragAndDrop::isInventoryDropAcceptable(obj, item))
 		{
diff --git a/indra/newview/llviewerfoldertype.cpp b/indra/newview/llviewerfoldertype.cpp
index dc95bf25c67..08713884aaa 100644
--- a/indra/newview/llviewerfoldertype.cpp
+++ b/indra/newview/llviewerfoldertype.cpp
@@ -292,14 +292,12 @@ const std::string &LLViewerFolderType::lookupNewCategoryName(LLFolderType::EType
 
 LLFolderType::EType LLViewerFolderType::lookupTypeFromNewCategoryName(const std::string& name)
 {
-	for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
-		 iter != LLViewerFolderDictionary::getInstance()->end();
-		 iter++)
+	for (const auto& pair : LLViewerFolderDictionary::instance())
 	{
-		const ViewerFolderEntry *entry = iter->second;
+		const ViewerFolderEntry *entry = pair.second;
 		if (entry->mNewCategoryName == name)
 		{
-			return iter->first;
+			return pair.first;
 		}
 	}
 	return FT_NONE;
@@ -309,14 +307,12 @@ LLFolderType::EType LLViewerFolderType::lookupTypeFromNewCategoryName(const std:
 U64 LLViewerFolderType::lookupValidFolderTypes(const std::string& item_name)
 {
 	U64 matching_folders = 0;
-	for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
-		 iter != LLViewerFolderDictionary::getInstance()->end();
-		 iter++)
+	for (const auto& pair : LLViewerFolderDictionary::instance())
 	{
-		const ViewerFolderEntry *entry = iter->second;
+		const ViewerFolderEntry *entry = pair.second;
 		if (entry->getIsAllowedName(item_name))
 		{
-			matching_folders |= 1LL << iter->first;
+			matching_folders |= 1LL << pair.first;
 		}
 	}
 	return matching_folders;
diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp
index e08a3dd2d38..72dc76be8ae 100644
--- a/indra/newview/llviewerinventory.cpp
+++ b/indra/newview/llviewerinventory.cpp
@@ -1110,16 +1110,12 @@ void create_inventory_item(const LLUUID& agent_id, const LLUUID& session_id,
 	std::string server_name = name;
 
 	{
-		std::map<std::string, std::string>::const_iterator dictionary_iter;
-
-		for (dictionary_iter = LLLocalizedInventoryItemsDictionary::getInstance()->mInventoryItemsDict.begin();
-			 dictionary_iter != LLLocalizedInventoryItemsDictionary::getInstance()->mInventoryItemsDict.end();
-			 dictionary_iter++)
+		for (const auto& pair : LLLocalizedInventoryItemsDictionary::getInstance()->mInventoryItemsDict)
 		{
-			const std::string& localized_name = dictionary_iter->second;
+			const std::string& localized_name = pair.second;
 			if(localized_name == name)
 			{
-				server_name = dictionary_iter->first;
+				server_name = pair.first;
 			}
 		}
 	}
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index 3056f454ac9..04ef12ed716 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -4788,9 +4788,10 @@ void handle_take()
 {
 	// we want to use the folder this was derezzed from if it's
 	// available. Otherwise, derez to the normal place.
+	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
 //	if(LLSelectMgr::getInstance()->getSelection()->isEmpty())
 // [RLVa:KB] - Checked: 2010-03-24 (RLVa-1.2.0e) | Modified: RLVa-1.0.0b
-	if ( (LLSelectMgr::getInstance()->getSelection()->isEmpty()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
+	if ( (selection->isEmpty()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
 // [/RLVa:KB]
 	{
 		return;
@@ -4800,10 +4801,8 @@ void handle_take()
 	BOOL locked_but_takeable_object = FALSE;
 	LLUUID category_id;
 	
-	for (LLObjectSelection::root_iterator iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->root_end(); iter++)
+	for (LLSelectNode* node : selection->root_begin_end())
 	{
-		LLSelectNode* node = *iter;
 		LLViewerObject* object = node->getObject();
 		if(object)
 		{
@@ -4876,7 +4875,7 @@ void handle_take()
 	// MAINT-290
 	// Reason: Showing the confirmation dialog resets object selection,	thus there is nothing to derez.
 	// Fix: pass selection to the confirm_take, so that selection doesn't "die" after confirmation dialog is opened
-	params.functor.function(boost::bind(confirm_take, _1, _2, LLSelectMgr::instance().getSelection()));
+	params.functor.function(boost::bind(confirm_take, _1, _2, selection));
 
 	if(locked_but_takeable_object ||
 	   !you_own_everything)
@@ -4952,10 +4951,8 @@ BOOL enable_take()
 		return FALSE;
 	}
 
-	for (LLObjectSelection::valid_root_iterator iter = LLSelectMgr::getInstance()->getSelection()->valid_root_begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->valid_root_end(); iter++)
+	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_root_begin_end())
 	{
-		LLSelectNode* node = *iter;
 		LLViewerObject* object = node->getObject();
 		if (object->isAvatar())
 		{
@@ -5069,10 +5066,8 @@ class LLToolsEnableBuyOrTake : public view_listener_t
 //                FALSE if selection is a 'take'
 BOOL is_selection_buy_not_take()
 {
-	for (LLObjectSelection::root_iterator iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->root_end(); iter++)
+	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
 	{
-		LLSelectNode* node = *iter;
 		LLViewerObject* obj = node->getObject();
 		if(obj && !(obj->permYouOwner()) && (node->mSaleInfo.isForSale()))
 		{
@@ -5092,10 +5087,8 @@ BOOL is_selection_buy_not_take()
 S32 selection_price()
 {
 	S32 total_price = 0;
-	for (LLObjectSelection::root_iterator iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->root_end(); iter++)
+	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
 	{
-		LLSelectNode* node = *iter;
 		LLViewerObject* obj = node->getObject();
 		if(obj && !(obj->permYouOwner()) && (node->mSaleInfo.isForSale()))
 		{
@@ -5275,10 +5268,8 @@ class LLToolsSnapObjectXY : public view_listener_t
 	{
 		F64 snap_size = (F64)ALControlCache::GridResolution;
 
-		for (LLObjectSelection::root_iterator iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
-			 iter != LLSelectMgr::getInstance()->getSelection()->root_end(); iter++)
+		for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
 		{
-			LLSelectNode* node = *iter;
 			LLViewerObject* obj = node->getObject();
 			if (obj->permModify())
 			{
@@ -7407,10 +7398,8 @@ BOOL object_is_wearable()
         return FALSE;
     }
 	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	for (LLObjectSelection::valid_root_iterator iter = LLSelectMgr::getInstance()->getSelection()->valid_root_begin();
-		 iter != LLSelectMgr::getInstance()->getSelection()->valid_root_end(); iter++)
+	for (LLSelectNode* node : selection->valid_root_begin_end())
 	{
-		LLSelectNode* node = *iter;		
 		if (node->mPermissions->getOwner() == gAgent.getID())
 		{
 			return TRUE;
@@ -7621,11 +7610,8 @@ class LLToolsSelectedScriptAction : public view_listener_t
 
 void handle_selected_texture_info(void*)
 {
-	for (LLObjectSelection::valid_iterator iter = LLSelectMgr::getInstance()->getSelection()->valid_begin();
-   		iter != LLSelectMgr::getInstance()->getSelection()->valid_end(); iter++)
+	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_begin_end())
 	{
-		LLSelectNode* node = *iter;
-	   	
    		std::string msg;
    		msg.assign("Texture info for: ");
    		msg.append(node->mName);
@@ -7668,11 +7654,8 @@ void handle_selected_texture_info(void*)
 
 void handle_selected_material_info()
 {
-	for (LLObjectSelection::valid_iterator iter = LLSelectMgr::getInstance()->getSelection()->valid_begin();
-		iter != LLSelectMgr::getInstance()->getSelection()->valid_end(); iter++)
+	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_begin_end())
 	{
-		LLSelectNode* node = *iter;
-		
 		std::string msg;
 		msg.assign("Material info for: \n");
 		msg.append(node->mName);
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index fe122fd7cb5..671661da14e 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -2739,17 +2739,12 @@ void LLVOAvatar::idleUpdateMisc(bool detailed_update)
 	{
 		LL_RECORD_BLOCK_TIME(FTM_ATTACHMENT_UPDATE);
 		auto& selectMgr = LLSelectMgr::instance();
-		for (attachment_map_t::iterator iter = mAttachmentPoints.begin(); 
-			 iter != mAttachmentPoints.end();
-			 ++iter)
+		for (const auto& attach_point_pair : mAttachmentPoints)
 		{
-			LLViewerJointAttachment* attachment = iter->second;
+			LLViewerJointAttachment* attachment = attach_point_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();
 				BOOL visibleAttachment = visible || (attached_object && 
 													 !(attached_object->mDrawable->getSpatialBridge() &&
 													   attached_object->mDrawable->getSpatialBridge()->getRadius() < 2.0));
-- 
GitLab