From 22e453c3bdbe2e222b79dfb5f93568c2ae8b2c34 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Wed, 19 Feb 2020 19:35:57 -0500
Subject: [PATCH] Clean up a bunch of bad LLSD loop usage

---
 indra/llcharacter/llbvhloader.cpp            |  4 ++--
 indra/llcommon/llmetricperformancetester.cpp |  2 +-
 indra/llcommon/llmetrics.cpp                 |  5 ++---
 indra/llcommon/llprocessor.cpp               |  7 ++++---
 indra/llcommon/llsdjson.cpp                  |  2 +-
 indra/llcommon/llsdparam.cpp                 |  4 ++--
 indra/llcommon/llsdserialize.cpp             | 10 ++++------
 indra/llcommon/llsdserialize_xml.cpp         |  5 ++---
 indra/llcommon/llsdutil.cpp                  | 11 ++++-------
 indra/llcommon/lluri.cpp                     |  5 ++---
 indra/llmessage/llavatarnamecache.cpp        |  3 +--
 indra/llmessage/llcachename.cpp              | 10 ++++------
 indra/llmessage/llexperiencecache.cpp        |  2 +-
 indra/llmessage/llfiltersd2xmlrpc.cpp        |  5 ++---
 indra/llmessage/lliohttpserver.cpp           |  4 +---
 indra/llui/llkeywords.cpp                    | 12 ++++--------
 indra/llui/llmultislider.cpp                 | 12 +++++-------
 indra/llui/llnotifications.cpp               |  4 ++--
 indra/llui/lluistring.cpp                    |  4 ++--
 indra/llxml/llcontrol.cpp                    |  2 +-
 indra/newview/alfloaterregiontracker.cpp     |  6 +++---
 indra/newview/llfavoritesbar.cpp             |  4 ++--
 indra/newview/llfloaterimsession.cpp         |  6 +++---
 indra/newview/llfloatermessagerewriter.cpp   |  3 +--
 indra/newview/llimview.cpp                   |  6 +++---
 indra/newview/llmutelist.cpp                 |  2 +-
 indra/newview/llpathfindingcharacterlist.cpp |  5 +++--
 indra/newview/llpathfindinglinksetlist.cpp   |  5 +++--
 indra/newview/llsecapicerthandler.cpp        | 12 ++++++------
 indra/newview/llspeakers.cpp                 | 15 +++++++++------
 indra/newview/lltexturefetch.cpp             |  3 +--
 indra/newview/llviewerregion.cpp             |  4 ++--
 indra/newview/llviewertexturelist.cpp        |  4 ++--
 indra/newview/llvoicechannel.cpp             |  3 +--
 indra/newview/llvoiceclient.cpp              |  4 ++--
 indra/newview/llwaterparamset.cpp            |  3 ++-
 indra/newview/llwaterparamset.h              |  2 +-
 indra/newview/llwebprofile.cpp               |  2 +-
 indra/newview/llwlparammanager.cpp           |  2 +-
 indra/newview/llwlparamset.cpp               |  4 ++--
 indra/newview/rlvcommon.cpp                  |  2 +-
 indra/newview/rlvfloaters.cpp                |  2 +-
 42 files changed, 98 insertions(+), 114 deletions(-)

diff --git a/indra/llcharacter/llbvhloader.cpp b/indra/llcharacter/llbvhloader.cpp
index 902adb4b11..dd99a734ce 100644
--- a/indra/llcharacter/llbvhloader.cpp
+++ b/indra/llcharacter/llbvhloader.cpp
@@ -505,8 +505,8 @@ ELoadStatus LLBVHLoader::loadAliases(const char * filename)
     {
         if ( LLSDSerialize::fromXML(aliases_sd, input_stream) )
         {
-            for(LLSD::map_iterator alias_iter = aliases_sd.beginMap();
-                alias_iter != aliases_sd.endMap();
+            for(LLSD::map_iterator alias_iter = aliases_sd.beginMap(), alias_end = aliases_sd.endMap();
+                alias_iter != alias_end;
                 ++alias_iter)
             {
                 LLSD::String alias_name = alias_iter->first;
diff --git a/indra/llcommon/llmetricperformancetester.cpp b/indra/llcommon/llmetricperformancetester.cpp
index 28ffac2d99..3a708ae039 100644
--- a/indra/llcommon/llmetricperformancetester.cpp
+++ b/indra/llcommon/llmetricperformancetester.cpp
@@ -103,7 +103,7 @@ LLSD LLMetricPerformanceTesterBasic::analyzeMetricPerformanceLog(std::istream& i
 	
 	while (!is.fail() && !is.eof() && LLSDParser::PARSE_FAILURE != LLSDSerialize::fromXML(cur, is))
 	{
-		for (auto iter = cur.beginMap(); iter != cur.endMap(); ++iter)
+		for (auto iter = cur.beginMap(), end = cur.endMap(); iter != end; ++iter)
 		{
 			std::string label = iter->first;
 			
diff --git a/indra/llcommon/llmetrics.cpp b/indra/llcommon/llmetrics.cpp
index 797180f353..81a343da14 100644
--- a/indra/llcommon/llmetrics.cpp
+++ b/indra/llcommon/llmetrics.cpp
@@ -105,9 +105,8 @@ void LLMetricsImpl::printTotals(LLSD metadata)
 		const std::string& location = (*loc_it).first;
 		
 		const LLSD& loc_map = (*loc_it).second;
-        auto mesg_it = loc_map.beginMap();
-        auto mesg_end = loc_map.endMap();
-		for ( ; mesg_it != mesg_end; ++mesg_it)
+		for (auto mesg_it = loc_map.beginMap(),
+			mesg_end = loc_map.endMap(); mesg_it != mesg_end; ++mesg_it)
 		{
 			const std::string& mesg = (*mesg_it).first;
 			const LLSD& mesg_map = (*mesg_it).second;
diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp
index a21056ca36..f8b82af49d 100644
--- a/indra/llcommon/llprocessor.cpp
+++ b/indra/llcommon/llprocessor.cpp
@@ -276,8 +276,8 @@ public:
 		out << "//////////////////////////" << std::endl;
 		
 		// Iterate through the dictionary of configuration options.
-		LLSD configs = mProcessorInfo["config"];
-		for(LLSD::map_const_iterator cfgItr = configs.beginMap(); cfgItr != configs.endMap(); ++cfgItr)
+		const LLSD& configs = mProcessorInfo["config"];
+		for(LLSD::map_const_iterator cfgItr = configs.beginMap(), cfgEnd = configs.endMap(); cfgItr != cfgEnd; ++cfgItr)
 		{
 			out << cfgItr->first << " = " << cfgItr->second << std::endl;
 		}
@@ -286,7 +286,8 @@ public:
 		out << "// CPU Extensions" << std::endl;
 		out << "//////////////////////////" << std::endl;
 		
-		for(auto itr = mProcessorInfo["extension"].beginMap(); itr != mProcessorInfo["extension"].endMap(); ++itr)
+		const LLSD& extensions = mProcessorInfo["extension"];
+		for(auto itr = extensions.beginMap(),  end = extensions.endMap(); itr != end; ++itr)
 		{
 			out << "  " << itr->first << std::endl;			
 		}
diff --git a/indra/llcommon/llsdjson.cpp b/indra/llcommon/llsdjson.cpp
index dc10535562..d2d28fb4dc 100644
--- a/indra/llcommon/llsdjson.cpp
+++ b/indra/llcommon/llsdjson.cpp
@@ -103,7 +103,7 @@ nlohmann::json LlsdToJson(const LLSD &val)
         result = val.asString();
         break;
     case LLSD::TypeMap:
-        for (auto it = val.beginMap(); it != val.endMap(); ++it)
+        for (auto it = val.beginMap(), it_end = val.endMap(); it != it_end; ++it)
         {
             result[it->first] = LlsdToJson(it->second);
         }
diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp
index decff2f121..78bf050f94 100644
--- a/indra/llcommon/llsdparam.cpp
+++ b/indra/llcommon/llsdparam.cpp
@@ -256,8 +256,8 @@ void LLParamSDParserUtilities::readSDValues(read_sd_cb_t cb, const LLSD& sd, LLI
 {
 	if (sd.isMap())
 	{
-		for (auto it = sd.beginMap();
-			it != sd.endMap();
+		for (auto it = sd.beginMap(), it_end = sd.endMap();
+			it != it_end;
 			++it)
 		{
 			stack.push_back(make_pair(it->first, true));
diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp
index 38e392ff6c..9631315f30 100644
--- a/indra/llcommon/llsdserialize.cpp
+++ b/indra/llcommon/llsdserialize.cpp
@@ -1298,9 +1298,8 @@ S32 LLSDNotationFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32
 		}
 
 		bool need_comma = false;
-        auto iter = data.beginMap();
-        auto end = data.endMap();
-		for(; iter != end; ++iter)
+        
+		for(auto iter = data.beginMap(), end = data.endMap(); iter != end; ++iter)
 		{
 			if(need_comma) ostr << ",";
 			need_comma = true;
@@ -1445,9 +1444,8 @@ S32 LLSDBinaryFormatter::format(const LLSD& data, std::ostream& ostr, U32 option
 		ostr.put('{');
 		U32 size_nbo = htonl(data.size());
 		ostr.write(reinterpret_cast<const char*>(&size_nbo), sizeof(U32));
-        auto iter = data.beginMap();
-        auto end = data.endMap();
-		for(; iter != end; ++iter)
+
+		for(auto iter = data.beginMap(), end = data.endMap(); iter != end; ++iter)
 		{
 			ostr.put('k');
 			formatString((*iter).first, ostr);
diff --git a/indra/llcommon/llsdserialize_xml.cpp b/indra/llcommon/llsdserialize_xml.cpp
index b0dfd63fff..0b9d3e2601 100644
--- a/indra/llcommon/llsdserialize_xml.cpp
+++ b/indra/llcommon/llsdserialize_xml.cpp
@@ -97,9 +97,8 @@ S32 LLSDXMLFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32 opti
 		else
 		{
 			ostr << pre << "<map>" << post;
-            auto iter = data.beginMap();
-            auto end = data.endMap();
-			for(; iter != end; ++iter)
+
+			for(auto iter = data.beginMap(), end = data.endMap(); iter != end; ++iter)
 			{
 				ostr << pre << "<key>" << escapeString((*iter).first) << "</key>" << post;
 				format_count += format_impl((*iter).second, ostr, options, level + 1);
diff --git a/indra/llcommon/llsdutil.cpp b/indra/llcommon/llsdutil.cpp
index c6f1e49b73..a98ad7da6b 100644
--- a/indra/llcommon/llsdutil.cpp
+++ b/indra/llcommon/llsdutil.cpp
@@ -276,12 +276,9 @@ BOOL compare_llsd_with_template(
 		//any excess is taken from the template
 		//excess is ignored in the test
 		LLSD value;
-		LLSD::map_const_iterator template_iter;
-
 		resultant_llsd = LLSD::emptyMap();
-		for (
-			template_iter = template_llsd.beginMap();
-			template_iter != template_llsd.endMap();
+		for (auto template_iter = template_llsd.beginMap(), template_end = template_llsd.endMap();
+			template_iter != template_end;
 			++template_iter)
 		{
 			if ( llsd_to_test.has(template_iter->first) )
@@ -492,7 +489,7 @@ std::string llsd_matches(const LLSD& prototype, const LLSD& data, const std::str
         out << colon(pfx);
         const char* init = "Map missing keys: ";
         const char* sep = init;
-        for (auto mi = prototype.beginMap(); mi != prototype.endMap(); ++mi)
+        for (auto mi = prototype.beginMap(), mi_end = prototype.endMap(); mi != mi_end; ++mi)
         {
             if (! data.has(mi->first))
             {
@@ -507,7 +504,7 @@ std::string llsd_matches(const LLSD& prototype, const LLSD& data, const std::str
         }
         // Good, the data block contains all the keys required by the
         // prototype. Now match the prototype entries.
-        for (auto mi2 = prototype.beginMap(); mi2 != prototype.endMap(); ++mi2)
+        for (auto mi2 = prototype.beginMap(), mi2_end = prototype.endMap(); mi2 != mi2_end; ++mi2)
         {
             std::string match(llsd_matches(mi2->second, data[mi2->first],
                                            STRINGIZE("['" << mi2->first << "']")));
diff --git a/indra/llcommon/lluri.cpp b/indra/llcommon/lluri.cpp
index 9b1ab4b89a..24faf755f7 100644
--- a/indra/llcommon/lluri.cpp
+++ b/indra/llcommon/lluri.cpp
@@ -740,10 +740,9 @@ std::string LLURI::mapToQueryString(const LLSD& queryMap)
 	if (queryMap.isMap())
 	{
 		bool first_element = true;
-        auto iter = queryMap.beginMap();
-        auto end = queryMap.endMap();
+
 		std::ostringstream ostr;
-		for (; iter != end; ++iter)
+		for (auto iter = queryMap.beginMap(), end = queryMap.endMap(); iter != end; ++iter)
 		{
 			if(first_element)
 			{
diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp
index 829dc09bde..7f5d274ad5 100644
--- a/indra/llmessage/llavatarnamecache.cpp
+++ b/indra/llmessage/llavatarnamecache.cpp
@@ -441,8 +441,7 @@ bool LLAvatarNameCache::importFile(std::istream& istr)
 
 	LLUUID agent_id;
 	LLAvatarName av_name;
-	LLSD::map_const_iterator it = agents.beginMap();
-	for ( ; it != agents.endMap(); ++it)
+	for (auto it = agents.beginMap(), end = agents.endMap(); it != end; ++it)
 	{
 		agent_id.set(it->first);
 		av_name.fromLLSD( it->second );
diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp
index a7765e9693..ea7d638a26 100644
--- a/indra/llmessage/llcachename.cpp
+++ b/indra/llmessage/llcachename.cpp
@@ -320,9 +320,7 @@ bool LLCacheName::importFile(std::istream& istr)
 	// iterate over the agents
 	S32 count = 0;
 	LLSD agents = data[AGENTS];
-	LLSD::map_iterator iter = agents.beginMap();
-	LLSD::map_iterator end = agents.endMap();
-	for( ; iter != end; ++iter)
+	for(auto iter = agents.beginMap(), end = agents.endMap(); iter != end; ++iter)
 	{
 		LLUUID id((*iter).first);
 		LLSD agent = (*iter).second;
@@ -344,9 +342,9 @@ bool LLCacheName::importFile(std::istream& istr)
 
 	count = 0;
 	LLSD groups = data[GROUPS];
-	iter = groups.beginMap();
-	end = groups.endMap();
-	for( ; iter != end; ++iter)
+
+	for(auto iter = groups.beginMap(),
+		end = groups.endMap(); iter != end; ++iter)
 	{
 		LLUUID id((*iter).first);
 		LLSD group = (*iter).second;
diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp
index 86417e1079..81984da589 100644
--- a/indra/llmessage/llexperiencecache.cpp
+++ b/indra/llmessage/llexperiencecache.cpp
@@ -136,7 +136,7 @@ void LLExperienceCache::importFile(std::istream& istr)
 
     LLUUID public_key;
     LLSD::map_const_iterator it = experiences.beginMap();
-    for (; it != experiences.endMap(); ++it)
+    for (auto it = experiences.beginMap(), end = experiences.endMap(); it != end; ++it)
     {
         public_key.set(it->first);
         mCache[public_key] = it->second;
diff --git a/indra/llmessage/llfiltersd2xmlrpc.cpp b/indra/llmessage/llfiltersd2xmlrpc.cpp
index 62e359bcd9..cc51601320 100644
--- a/indra/llmessage/llfiltersd2xmlrpc.cpp
+++ b/indra/llmessage/llfiltersd2xmlrpc.cpp
@@ -171,9 +171,8 @@ void LLFilterSD2XMLRPC::streamOut(std::ostream& ostr, const LLSD& sd)
 		{
 			LL_INFOS() << "STREAM FAILURE writing struct" << LL_ENDL;
 		}
-		LLSD::map_const_iterator it = sd.beginMap();
-		LLSD::map_const_iterator end = sd.endMap();
-		for(; it != end; ++it)
+		for(auto it = sd.beginMap(), end = sd.endMap(); 
+			it != end; ++it)
 		{
 			ostr << "<member><name>" << xml_escape_string((*it).first)
 				<< "</name>";
diff --git a/indra/llmessage/lliohttpserver.cpp b/indra/llmessage/lliohttpserver.cpp
index 15d1203c35..18cc5918e7 100644
--- a/indra/llmessage/lliohttpserver.cpp
+++ b/indra/llmessage/lliohttpserver.cpp
@@ -494,9 +494,7 @@ LLIOPipe::EStatus LLHTTPResponseHeader::process_impl(
 		LLSD headers = context[CONTEXT_RESPONSE][CONTEXT_HEADERS];
 		if(headers.isDefined())
 		{
-			LLSD::map_iterator iter = headers.beginMap();
-			LLSD::map_iterator end = headers.endMap();
-			for(; iter != end; ++iter)
+			for(auto iter = headers.beginMap(), end = headers.endMap(); iter != end; ++iter)
 			{
 				ostr << (*iter).first << ": " << (*iter).second.asString()
 					<< "\r\n";
diff --git a/indra/llui/llkeywords.cpp b/indra/llui/llkeywords.cpp
index 11b35663ca..36aed4f6bc 100644
--- a/indra/llui/llkeywords.cpp
+++ b/indra/llui/llkeywords.cpp
@@ -141,8 +141,7 @@ std::string LLKeywords::getArguments(LLSD& arguments)
 			LLSD& args = (*arrayIt);
 			if (args.isMap())
 			{
-				LLSD::map_iterator argsIt = args.beginMap();
-				for ( ; argsIt != args.endMap(); ++argsIt)
+				for (LLSD::map_const_iterator argsIt = args.beginMap(), argsEnd = args.endMap(); argsIt != argsEnd; ++argsIt)
 				{
 					argString += argsIt->second.get("type").asString() + " " + argsIt->first;
 					if (argsCount-- > 1)
@@ -239,8 +238,7 @@ void LLKeywords::processTokens()
 	addToken(LLKeywordToken::TT_TWO_SIDED_DELIMITER, "/*", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (multi-line)\nNon-functional commentary or disabled code", "*/" );
 	addToken(LLKeywordToken::TT_DOUBLE_QUOTATION_MARKS, "\"", LLUIColorTable::instance().getColor("SyntaxLslStringLiteral"), "String literal", "\"" );
 
-	LLSD::map_iterator itr = mSyntax.beginMap();
-	for ( ; itr != mSyntax.endMap(); ++itr)
+	for (auto itr = mSyntax.beginMap(), ite = mSyntax.endMap(); itr != ite; ++itr)
 	{
 		if (itr->first == "llsd-lsl-syntax-version")
 		{
@@ -300,15 +298,13 @@ void LLKeywords::processTokensGroup(const LLSD& tokens, const std::string& group
 
 	if (tokens.isMap())
 	{
-		LLSD::map_const_iterator outer_itr = tokens.beginMap();
-		for ( ; outer_itr != tokens.endMap(); ++outer_itr )
+		for (auto outer_itr = tokens.beginMap(), outer_ite = tokens.endMap(); outer_itr != outer_ite; ++outer_itr )
 		{
 			if (outer_itr->second.isMap())
 			{
 				mAttributes.clear();
 				LLSD arguments = LLSD();
-				LLSD::map_const_iterator inner_itr = outer_itr->second.beginMap();
-				for ( ; inner_itr != outer_itr->second.endMap(); ++inner_itr )
+				for (auto inner_itr = outer_itr->second.beginMap(), inner_ite = outer_itr->second.endMap(); inner_itr != inner_ite; ++inner_itr )
 				{
 					if (inner_itr->first == "arguments")
 					{ 
diff --git a/indra/llui/llmultislider.cpp b/indra/llui/llmultislider.cpp
index b6be4eba6c..fd7c3ac971 100644
--- a/indra/llui/llmultislider.cpp
+++ b/indra/llui/llmultislider.cpp
@@ -140,9 +140,8 @@ void LLMultiSlider::setSliderValue(const std::string& name, F32 value, BOOL from
 
 		// look at the current spot
 		// and see if anything is there
-		LLSD::map_iterator mIt = mValue.beginMap();
-		for(;mIt != mValue.endMap(); mIt++) {
-			
+		for( auto mIt = mValue.beginMap(), multEnd = mValue.endMap(); mIt != multEnd; ++mIt)
+		{
 			F32 testVal = (F32)mIt->second.asReal() - newValue;
 			if(testVal > -FLOAT_THRESHOLD && testVal < FLOAT_THRESHOLD &&
 				mIt->first != name) {
@@ -186,7 +185,7 @@ void LLMultiSlider::setValue(const LLSD& value)
 		LLSD::map_const_iterator mIt = value.beginMap();
 		mCurSlider = mIt->first;
 
-		for(; mIt != value.endMap(); mIt++) {
+		for(auto mEnd = value.endMap(); mIt != mEnd; ++mIt) {
 			setSliderValue(mIt->first, (F32)mIt->second.asReal(), TRUE);
 		}
 	}
@@ -276,9 +275,8 @@ bool LLMultiSlider::findUnusedValue(F32& initVal)
 
 		// look at the current spot
 		// and see if anything is there
-		LLSD::map_iterator mIt = mValue.beginMap();
-		for(;mIt != mValue.endMap(); mIt++) {
-			
+		for (auto mIt = mValue.beginMap(), multEnd = mValue.endMap(); mIt != multEnd; ++mIt)
+		{
 			F32 testVal = (F32)mIt->second.asReal() - initVal;
 			if(testVal > -FLOAT_THRESHOLD && testVal < FLOAT_THRESHOLD) {
 				hit = true;
diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp
index 53b1003598..5366a5d6b6 100644
--- a/indra/llui/llnotifications.cpp
+++ b/indra/llui/llnotifications.cpp
@@ -652,8 +652,8 @@ S32 LLNotification::getSelectedOption(const LLSD& notification, const LLSD& resp
 //static
 std::string LLNotification::getSelectedOptionName(const LLSD& response)
 {
-	for (LLSD::map_const_iterator response_it = response.beginMap();
-		response_it != response.endMap();
+	for (LLSD::map_const_iterator response_it = response.beginMap(), response_end = response.endMap();
+		response_it != response_end;
 		++response_it)
 	{
 		if (response_it->second.isBoolean() && response_it->second.asBoolean())
diff --git a/indra/llui/lluistring.cpp b/indra/llui/lluistring.cpp
index 6ef16f072a..c1d4255bad 100644
--- a/indra/llui/lluistring.cpp
+++ b/indra/llui/lluistring.cpp
@@ -61,8 +61,8 @@ void LLUIString::setArgs(const LLSD& sd)
 	LL_RECORD_BLOCK_TIME(FTM_UI_STRING);
 	
 	if (!sd.isMap()) return;
-	for(LLSD::map_const_iterator sd_it = sd.beginMap();
-		sd_it != sd.endMap();
+	for(LLSD::map_const_iterator sd_it = sd.beginMap(), sd_end = sd.endMap();
+		sd_it != sd_end;
 		++sd_it)
 	{
 		setArg(sd_it->first, sd_it->second.asString());
diff --git a/indra/llxml/llcontrol.cpp b/indra/llxml/llcontrol.cpp
index fb82d351d6..697430635b 100644
--- a/indra/llxml/llcontrol.cpp
+++ b/indra/llxml/llcontrol.cpp
@@ -997,7 +997,7 @@ U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_v
 	U32	validitems = 0;
 	bool hidefromsettingseditor = false;
 	
-	for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr)
+	for(LLSD::map_const_iterator itr = settings.beginMap(), ite = settings.endMap(); itr != ite; ++itr)
 	{
 		LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT;
 		std::string const & name = itr->first;
diff --git a/indra/newview/alfloaterregiontracker.cpp b/indra/newview/alfloaterregiontracker.cpp
index d3954d6fbb..c7d9a7f18d 100644
--- a/indra/newview/alfloaterregiontracker.cpp
+++ b/indra/newview/alfloaterregiontracker.cpp
@@ -115,7 +115,7 @@ void ALFloaterRegionTracker::refresh()
 
 	const std::string& cur_region_name = gAgent.getRegion() ? gAgent.getRegion()->getName() : LLStringUtil::null;
 
-	for (LLSD::map_const_iterator it = mRegionMap.beginMap(); it != mRegionMap.endMap(); it++)
+	for (LLSD::map_const_iterator it = mRegionMap.beginMap(), end = mRegionMap.endMap(); it != end; it++)
 	{
 		const std::string& sim_name = it->first;
 		const LLSD& data = it->second;
@@ -181,7 +181,7 @@ void ALFloaterRegionTracker::requestRegionData()
 	if (!mRegionMap.size())
 		return;
 
-	for (LLSD::map_const_iterator it = mRegionMap.beginMap(); it != mRegionMap.endMap(); it++)
+	for (LLSD::map_const_iterator it = mRegionMap.beginMap(), end = mRegionMap.endMap(); it != end; ++it)
 	{
 		const auto& name = it->first;
 		if (LLSimInfo* info = LLWorldMap::getInstance()->simInfoFromName(name))
@@ -252,7 +252,7 @@ void ALFloaterRegionTracker::onRegionAddedCallback(const LLSD& notification, con
 		{
 			if (mRegionMap.has(name))
 			{
-				for (LLSD::map_iterator it = mRegionMap.beginMap(); it != mRegionMap.endMap(); it++)
+				for (LLSD::map_iterator it = mRegionMap.beginMap(), end = mRegionMap.endMap(); it != end; ++it)
 					if (it->first == name) it->second["label"] = label;
 			}
 			else
diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp
index cffed379f8..d8c4d5c279 100644
--- a/indra/newview/llfavoritesbar.cpp
+++ b/indra/newview/llfavoritesbar.cpp
@@ -1525,8 +1525,8 @@ void LLFavoritesOrderStorage::load()
         LL_WARNS("FavoritesBar") << "unable to open favorites order file at '" << filename << "'" << LL_ENDL;
     }
 
-	for (LLSD::map_const_iterator iter = settings_llsd.beginMap();
-		iter != settings_llsd.endMap(); ++iter)
+	for (LLSD::map_const_iterator iter = settings_llsd.beginMap(), end = settings_llsd.endMap();
+		iter != end; ++iter)
 	{
 		mSortIndexes.insert(std::make_pair(LLUUID(iter->first), (S32)iter->second.asInteger()));
 	}
diff --git a/indra/newview/llfloaterimsession.cpp b/indra/newview/llfloaterimsession.cpp
index c6e983abb5..7e5c6a8d0f 100644
--- a/indra/newview/llfloaterimsession.cpp
+++ b/indra/newview/llfloaterimsession.cpp
@@ -1089,9 +1089,9 @@ void LLFloaterIMSession::processAgentListUpdates(const LLSD& body)
 
 	if (body.isMap() && body.has("agent_updates") && body["agent_updates"].isMap())
 	{
-		LLSD::map_const_iterator update_it;
-		for(update_it = body["agent_updates"].beginMap();
-			update_it != body["agent_updates"].endMap();
+		const LLSD& agent_updates = body["agent_updates"];
+		for(LLSD::map_const_iterator update_it = agent_updates.beginMap(), update_end = agent_updates.endMap();
+			update_it != update_end;
 			++update_it)
 		{
 			LLUUID agent_id(update_it->first);
diff --git a/indra/newview/llfloatermessagerewriter.cpp b/indra/newview/llfloatermessagerewriter.cpp
index 8baae5aa0a..8aa05ea422 100644
--- a/indra/newview/llfloatermessagerewriter.cpp
+++ b/indra/newview/llfloatermessagerewriter.cpp
@@ -81,8 +81,7 @@ void LLFloaterMessageRewriter::refreshRuleList()
 	
 	LLSD& messages = LLMessageConfigFile::instance().mMessages;
 	
-	LLSD::map_iterator map_end = messages.endMap();
-	for(LLSD::map_iterator map_iter = messages.beginMap() ; map_iter != map_end; ++map_iter)
+	for(LLSD::map_iterator map_iter = messages.beginMap(), map_end = messages.endMap(); map_iter != map_end; ++map_iter)
 	{
 		std::string key((*map_iter).first);
 		messageChooser->add(key, ADD_BOTTOM, true);
diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp
index 14d1783c35..827a6d2bd7 100644
--- a/indra/newview/llimview.cpp
+++ b/indra/newview/llimview.cpp
@@ -3270,9 +3270,9 @@ void LLIMMgr::addPendingAgentListUpdates(
 		//of agent_id -> "LEAVE"/"ENTER"
 
 		//only want to keep last update for each agent
-		for (
-			iter = updates["updates"].beginMap();
-			iter != updates["updates"].endMap();
+		const LLSD& update = updates["updates"];
+		for (auto iter = update.beginMap(), end = update.endMap();
+			iter != end;
 			++iter)
 		{
 			mPendingAgentListUpdates[session_id.asString()]["updates"][iter->first] =
diff --git a/indra/newview/llmutelist.cpp b/indra/newview/llmutelist.cpp
index 6bc386640a..e40790d431 100644
--- a/indra/newview/llmutelist.cpp
+++ b/indra/newview/llmutelist.cpp
@@ -876,7 +876,7 @@ bool LLRenderMuteList::loadFromFile()
 
 	if (visual_mute_settings.isMap() && visual_mute_settings.size() > 0)
 	{
-		for (auto it = visual_mute_settings.beginMap(); it != visual_mute_settings.endMap(); ++it)
+		for (auto it = visual_mute_settings.beginMap(), end = visual_mute_settings.endMap(); it != end; ++it)
 		{
 			LLUUID agent_id(it->first);
 			if (agent_id.isNull())
diff --git a/indra/newview/llpathfindingcharacterlist.cpp b/indra/newview/llpathfindingcharacterlist.cpp
index d63daaa59b..cd0a32cad2 100644
--- a/indra/newview/llpathfindingcharacterlist.cpp
+++ b/indra/newview/llpathfindingcharacterlist.cpp
@@ -58,8 +58,9 @@ void LLPathfindingCharacterList::parseCharacterListData(const LLSD& pCharacterLi
 {
     LLPathfindingObjectMap &objectMap = getObjectMap();
 
-    for (LLSD::map_const_iterator characterDataIter = pCharacterListData.beginMap();
-        characterDataIter != pCharacterListData.endMap(); ++characterDataIter)
+    for (LLSD::map_const_iterator characterDataIter = pCharacterListData.beginMap(), 
+        characterDataEnd = pCharacterListData.endMap();
+        characterDataIter != characterDataEnd; ++characterDataIter)
     {
         if (characterDataIter->second.isUndefined())
             continue;
diff --git a/indra/newview/llpathfindinglinksetlist.cpp b/indra/newview/llpathfindinglinksetlist.cpp
index 100b7fbae6..59718aad61 100644
--- a/indra/newview/llpathfindinglinksetlist.cpp
+++ b/indra/newview/llpathfindinglinksetlist.cpp
@@ -196,8 +196,9 @@ void LLPathfindingLinksetList::parseLinksetListData(const LLSD& pLinksetListData
 {
 	LLPathfindingObjectMap &objectMap = getObjectMap();
 
-	for (LLSD::map_const_iterator linksetDataIter = pLinksetListData.beginMap();
-		linksetDataIter != pLinksetListData.endMap(); ++linksetDataIter)
+	for (LLSD::map_const_iterator linksetDataIter = pLinksetListData.beginMap(),
+		linksetDataEnd = pLinksetListData.endMap();
+		linksetDataIter != linksetDataEnd; ++linksetDataIter)
 	{
 		const std::string& uuid(linksetDataIter->first);
 		const LLSD& linksetData = linksetDataIter->second;
diff --git a/indra/newview/llsecapicerthandler.cpp b/indra/newview/llsecapicerthandler.cpp
index a5558afa9a..1a7d690d10 100644
--- a/indra/newview/llsecapicerthandler.cpp
+++ b/indra/newview/llsecapicerthandler.cpp
@@ -63,8 +63,8 @@ bool valueCompareLLSD(const LLSD& lhs, const LLSD& rhs)
     {
         // iterate through the map, verifying the right hand side has all of the
         // values that the left hand side has.
-        for (LLSD::map_const_iterator litt = lhs.beginMap();
-             litt != lhs.endMap();
+        for (LLSD::map_const_iterator litt = lhs.beginMap(), lite = lhs.endMap();
+             litt != lite;
              ++litt)
         {
             if (!rhs.has(litt->first))
@@ -75,8 +75,8 @@ bool valueCompareLLSD(const LLSD& lhs, const LLSD& rhs)
         
         // Now validate that the left hand side has everything the
         // right hand side has, and that the values are equal.
-        for (LLSD::map_const_iterator ritt = rhs.beginMap();
-             ritt != rhs.endMap();
+        for (LLSD::map_const_iterator ritt = rhs.beginMap(), rite = rhs.endMap();
+             ritt != rite;
              ++ritt)
         {
             if (!lhs.has(ritt->first))
@@ -554,8 +554,8 @@ LLBasicCertificateVector::iterator LLBasicCertificateVector::find(const LLSD& pa
         found = true;
         LLSD cert_info;
         (*cert)->getLLSD(cert_info);
-        for (LLSD::map_const_iterator param = params.beginMap();
-             found && param != params.endMap();
+        for (LLSD::map_const_iterator param = params.beginMap(), param_end = params.endMap();
+             found && param != param_end;
              ++param)
         {
             if (   !cert_info.has(static_cast<std::string>(param->first))
diff --git a/indra/newview/llspeakers.cpp b/indra/newview/llspeakers.cpp
index d3e62748e7..879790abc2 100644
--- a/indra/newview/llspeakers.cpp
+++ b/indra/newview/llspeakers.cpp
@@ -676,8 +676,9 @@ void LLIMSpeakerMgr::setSpeakers(const LLSD& speakers)
 
 	if ( speakers.has("agent_info") && speakers["agent_info"].isMap() )
 	{
-		for(LLSD::map_const_iterator speaker_it = speakers["agent_info"].beginMap();
-			speaker_it != speakers["agent_info"].endMap();
+		const LLSD& agent_info = speakers["agent_info"];
+		for(LLSD::map_const_iterator speaker_it = agent_info.beginMap(), speaker_end = agent_info.endMap();
+			speaker_it != speaker_end;
 			++speaker_it)
 		{
 			LLUUID agent_id(speaker_it->first);
@@ -724,8 +725,9 @@ void LLIMSpeakerMgr::updateSpeakers(const LLSD& update)
 
 	if ( update.has("agent_updates") && update["agent_updates"].isMap() )
 	{
-		for(LLSD::map_const_iterator update_it = update["agent_updates"].beginMap();
-			update_it != update["agent_updates"].endMap();
+		const LLSD& agent_update = update["agent_updates"];
+		for(LLSD::map_const_iterator update_it = agent_update.beginMap(), update_end = agent_update.endMap();
+			update_it != update_end;
 			++update_it)
 		{
 			LLUUID agent_id(update_it->first);
@@ -778,8 +780,9 @@ void LLIMSpeakerMgr::updateSpeakers(const LLSD& update)
 	}
 	else if ( update.has("updates") && update["updates"].isMap() )
 	{
-		for (LLSD::map_const_iterator update_it = update["updates"].beginMap();
-			 update_it != update["updates"].endMap();
+		const LLSD& update_ref = update["updates"];
+		for (LLSD::map_const_iterator update_it = update_ref.beginMap(), update_end = update_ref.endMap();
+			 update_it != update_end;
 			 ++update_it)
 		{
 			LLUUID agent_id(update_it->first);
diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp
index 31526e6d0e..c523b920df 100644
--- a/indra/newview/lltexturefetch.cpp
+++ b/indra/newview/lltexturefetch.cpp
@@ -4073,8 +4073,7 @@ truncate_viewer_metrics(int max_regions, LLSD & metrics)
 	reg_ordered_list_t regions_by_duration;
 
 	int ind(0);
-	LLSD::array_const_iterator it_end(reg_map.endArray());
-	for (LLSD::array_const_iterator it(reg_map.beginArray()); it_end != it; ++it, ++ind)
+	for (LLSD::array_const_iterator it(reg_map.beginArray()), it_end(reg_map.endArray()); it_end != it; ++it, ++ind)
 	{
 		LLSD::Real duration = (*it)[duration_tag].asReal();
 		regions_by_duration.insert(reg_ordered_list_t::value_type(duration, ind));
diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index 5fe37e7940..4770c5a351 100644
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -330,7 +330,7 @@ void LLViewerRegionImpl::requestBaseCapabilitiesCoro(U64 regionHandle)
         // remove the http_result from the llsd
         result.erase("http_result");
 
-	    for (LLSD::map_const_iterator iter = result.beginMap(); iter != result.endMap(); ++iter)
+	    for (LLSD::map_const_iterator iter = result.beginMap(), end = result.endMap(); iter != end; ++iter)
         {
             regionp->setCapability(iter->first, iter->second);
 
@@ -418,7 +418,7 @@ void LLViewerRegionImpl::requestBaseCapabilitiesCompleteCoro(U64 regionHandle)
         // remove the http_result from the llsd
         result.erase("http_result");
 
-	    for (LLSD::map_const_iterator iter = result.beginMap(); iter != result.endMap(); ++iter)
+	    for (LLSD::map_const_iterator iter = result.beginMap(), end = result.endMap(); iter != end; ++iter)
         {
             regionp->setCapabilityDebug(iter->first, iter->second);
             //LL_INFOS()<<"BaseCapabilitiesCompleteTracker New Caps "<<iter->first<<" "<< iter->second<<LL_ENDL;
diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp
index 201c88886e..a9b6731ecd 100644
--- a/indra/newview/llviewertexturelist.cpp
+++ b/indra/newview/llviewertexturelist.cpp
@@ -231,8 +231,8 @@ void LLViewerTextureList::doPrefetchImages()
         file.close();
 	}
     S32 texture_count = 0;
-	for (LLSD::array_iterator iter = imagelist.beginArray();
-		 iter != imagelist.endArray(); ++iter)
+	for (LLSD::array_iterator iter = imagelist.beginArray(), end = imagelist.endArray();
+		 iter != end; ++iter)
 	{
 		LLSD imagesd = *iter;
 		LLUUID uuid = imagesd["uuid"];
diff --git a/indra/newview/llvoicechannel.cpp b/indra/newview/llvoicechannel.cpp
index 10f6ce4f78..f561db8b29 100644
--- a/indra/newview/llvoicechannel.cpp
+++ b/indra/newview/llvoicechannel.cpp
@@ -645,8 +645,7 @@ void LLVoiceChannelGroup::voiceCallCapCoro(std::string url)
 
     result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
 
-    LLSD::map_const_iterator iter;
-    for (iter = result.beginMap(); iter != result.endMap(); ++iter)
+    for (LLSD::map_const_iterator iter = result.beginMap(), end = result.endMap(); iter != end; ++iter)
     {
         LL_DEBUGS("Voice") << "LLVoiceCallCapResponder::result got "
             << iter->first << LL_ENDL;
diff --git a/indra/newview/llvoiceclient.cpp b/indra/newview/llvoiceclient.cpp
index e4212a5b9f..8fe13a1c88 100644
--- a/indra/newview/llvoiceclient.cpp
+++ b/indra/newview/llvoiceclient.cpp
@@ -1085,8 +1085,8 @@ void LLSpeakerVolumeStorage::load()
             
 	}
 
-	for (LLSD::map_const_iterator iter = settings_llsd.beginMap();
-		iter != settings_llsd.endMap(); ++iter)
+	for (LLSD::map_const_iterator iter = settings_llsd.beginMap(), iter_end = settings_llsd.endMap();
+		iter != iter_end; ++iter)
 	{
 		// Maintain compatibility with 1.23 non-linear saved volume levels
 		F32 volume = transformFromLegacyVolume((F32)iter->second.asReal());
diff --git a/indra/newview/llwaterparamset.cpp b/indra/newview/llwaterparamset.cpp
index 7418a92668..071105c5db 100644
--- a/indra/newview/llwaterparamset.cpp
+++ b/indra/newview/llwaterparamset.cpp
@@ -230,7 +230,8 @@ void LLWaterParamSet::mix(LLWaterParamSet& src, LLWaterParamSet& dest, F32 weigh
 	LLSD srcVal, destVal;													// LLSD holders for get/set calls, reusable
 
 	// Iterate through values
-	for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
+	for(LLSD::map_iterator iter = mParamValues.beginMap(), 
+		iter_end = mParamValues.endMap(); iter != iter_end; ++iter)
 	{
 		// If param exists in both src and dest, set the holder variables, otherwise skip
 		if(src.mParamValues.has(iter->first) && dest.mParamValues.has(iter->first))
diff --git a/indra/newview/llwaterparamset.h b/indra/newview/llwaterparamset.h
index 75729e68bc..1ddec9e116 100644
--- a/indra/newview/llwaterparamset.h
+++ b/indra/newview/llwaterparamset.h
@@ -145,7 +145,7 @@ inline void LLWaterParamSet::updateHashedNames()
 {
 	mParamHashedNames.clear();
 	// Iterate through values
-	for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
+	for(LLSD::map_iterator iter = mParamValues.beginMap(), end = mParamValues.endMap(); iter != end; ++iter)
 	{
 		mParamHashedNames.emplace_back(iter->first);
 	}
diff --git a/indra/newview/llwebprofile.cpp b/indra/newview/llwebprofile.cpp
index dbfd0eba1b..184286c047 100644
--- a/indra/newview/llwebprofile.cpp
+++ b/indra/newview/llwebprofile.cpp
@@ -84,7 +84,7 @@ LLCore::HttpHeaders::ptr_t LLWebProfile::buildDefaultHeaders()
     auto httpHeaders = std::make_shared<LLCore::HttpHeaders>();
     LLSD headers = LLViewerMedia::getInstance()->getHeaders();
 
-    for (LLSD::map_iterator it = headers.beginMap(); it != headers.endMap(); ++it)
+    for (LLSD::map_iterator it = headers.beginMap(), end = headers.endMap(); it != end; ++it)
     {
         httpHeaders->append((*it).first, (*it).second.asStringRef());
     }
diff --git a/indra/newview/llwlparammanager.cpp b/indra/newview/llwlparammanager.cpp
index ae880dac94..9c45f7edec 100644
--- a/indra/newview/llwlparammanager.cpp
+++ b/indra/newview/llwlparammanager.cpp
@@ -242,7 +242,7 @@ LLSD LLWLParamManager::createSkyMap(std::map<LLWLParamKey, LLWLParamSet> refs)
 
 void LLWLParamManager::addAllSkies(const LLWLParamKey::EScope scope, const LLSD& sky_presets)
 {
-	for(LLSD::map_const_iterator iter = sky_presets.beginMap(); iter != sky_presets.endMap(); ++iter)
+	for(LLSD::map_const_iterator iter = sky_presets.beginMap(), end = sky_presets.endMap(); iter != end; ++iter)
 	{
 		LLWLParamSet set;
 		set.setAll(iter->second);
diff --git a/indra/newview/llwlparamset.cpp b/indra/newview/llwlparamset.cpp
index 4f9caeccb9..3923f60d74 100644
--- a/indra/newview/llwlparamset.cpp
+++ b/indra/newview/llwlparamset.cpp
@@ -291,7 +291,7 @@ void LLWLParamSet::mix(LLWLParamSet& src, LLWLParamSet& dest, F32 weight)
 	LLSD destVal;
 
 	// Iterate through values
-	for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
+	for(auto iter = mParamValues.beginMap(), end = mParamValues.endMap(); iter != end; ++iter)
 	{
 		// If param exists in both src and dest, set the holder variables, otherwise skip
 		if(src.mParamValues.has(iter->first) && dest.mParamValues.has(iter->first))
@@ -398,7 +398,7 @@ void LLWLParamSet::updateHashedNames()
 {
 	mParamHashedNames.clear();
 	// Iterate through values
-	for(auto iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
+	for(auto iter = mParamValues.beginMap(), end = mParamValues.endMap(); iter != end; ++iter)
 	{
 		mParamHashedNames.emplace_back(iter->first);
 	}
diff --git a/indra/newview/rlvcommon.cpp b/indra/newview/rlvcommon.cpp
index 50ca8daaae..131e2822d6 100644
--- a/indra/newview/rlvcommon.cpp
+++ b/indra/newview/rlvcommon.cpp
@@ -291,7 +291,7 @@ void RlvStrings::loadFromFile(const std::string& strFilePath, bool fUserOverride
 	if (sdFileData.has("strings"))
 	{
 		const LLSD& sdStrings = sdFileData["strings"];
-		for (LLSD::map_const_iterator itString = sdStrings.beginMap(); itString != sdStrings.endMap(); ++itString)
+		for (LLSD::map_const_iterator itString = sdStrings.beginMap(), itEnd = sdStrings.endMap(); itString != itEnd; ++itString)
 		{
 			if ( (!itString->second.has("value")) || ((fUserOverride) && (!hasString(itString->first))) )
 				continue;
diff --git a/indra/newview/rlvfloaters.cpp b/indra/newview/rlvfloaters.cpp
index 3b45370805..1414a67ef3 100644
--- a/indra/newview/rlvfloaters.cpp
+++ b/indra/newview/rlvfloaters.cpp
@@ -651,7 +651,7 @@ BOOL RlvFloaterStrings::postBuild()
 	}
 
 	// Populate the combo box
-	for (LLSD::map_const_iterator itString = m_sdStringsInfo.beginMap(); itString != m_sdStringsInfo.endMap(); ++itString)
+	for (LLSD::map_const_iterator itString = m_sdStringsInfo.beginMap(), itEnd = m_sdStringsInfo.endMap(); itString != itEnd; ++itString)
 	{
 		const LLSD& sdStringInfo = itString->second;
 		if ( (!sdStringInfo.has("customizable")) || (!sdStringInfo["customizable"].asBoolean()) )
-- 
GitLab