From 629eb0a18a3580d27e82faaf30860b48818e84b3 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Mon, 20 Jul 2020 17:31:29 -0400
Subject: [PATCH] Cleanup various double finds and bad map access patterns

---
 indra/llappearance/lldriverparam.cpp | 20 ++++++++++----------
 indra/llappearance/llpolymorph.cpp   |  4 ++--
 indra/llappearance/llwearable.cpp    | 21 +++++++++++----------
 indra/llcharacter/llpose.cpp         |  9 ++++-----
 indra/llcommon/llfasttimer.cpp       |  8 ++++----
 5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/indra/llappearance/lldriverparam.cpp b/indra/llappearance/lldriverparam.cpp
index f49ad9826fb..062f9ceddea 100644
--- a/indra/llappearance/lldriverparam.cpp
+++ b/indra/llappearance/lldriverparam.cpp
@@ -232,19 +232,19 @@ void LLDriverParam::setWeight(F32 weight)
 	//-------|----|-------|----|-------> driver
 	//  | min1   max1    max2  min2
 
-	for( entry_list_t::iterator iter = mDriven.begin(); iter != mDriven.end(); iter++ )
+	for(LLDrivenEntry& driven : mDriven )
 	{
-		LLDrivenEntry* driven = &(*iter);
-		LLDrivenEntryInfo* info = driven->mInfo;
+		LLDrivenEntryInfo* info = driven.mInfo;
+		LLViewerVisualParam* driven_param = driven.mParam;
 		
 		F32 driven_weight = 0.f;
-		F32 driven_min = driven->mParam->getMinWeight();
-		F32 driven_max = driven->mParam->getMaxWeight();
+		F32 driven_min = driven_param->getMinWeight();
+		F32 driven_max = driven_param->getMaxWeight();
 
 		if (mIsAnimating)
 		{
 			// driven param doesn't interpolate (textures, for example)
-			if (!driven->mParam->getAnimating())
+			if (!driven_param->getAnimating())
 			{
 				continue;
 			}
@@ -268,7 +268,7 @@ void LLDriverParam::setWeight(F32 weight)
 					driven_weight = driven_min;
 				}
 				
-				setDrivenWeight(driven,driven_weight);
+				setDrivenWeight(&driven,driven_weight);
 				continue;
 			}
 			else 
@@ -292,13 +292,13 @@ void LLDriverParam::setWeight(F32 weight)
 					driven_weight = driven_min;
 				}
 
-				setDrivenWeight(driven,driven_weight);
+				setDrivenWeight(&driven,driven_weight);
 				continue;
 			}
 		}
 
-		driven_weight = getDrivenWeight(driven, mCurWeight);
-		setDrivenWeight(driven,driven_weight);
+		driven_weight = getDrivenWeight(&driven, mCurWeight);
+		setDrivenWeight(&driven,driven_weight);
 	}
 }
 
diff --git a/indra/llappearance/llpolymorph.cpp b/indra/llappearance/llpolymorph.cpp
index 66e9751f062..3f0423fc498 100644
--- a/indra/llappearance/llpolymorph.cpp
+++ b/indra/llappearance/llpolymorph.cpp
@@ -555,11 +555,11 @@ void LLPolyMorphTarget::apply( ESex avatar_sex )
 	// Check for NaN condition (NaN is detected if a variable doesn't equal itself.
 	if (mCurWeight != mCurWeight)
 	{
-		mCurWeight = 0.0;
+		mCurWeight = 0.0f;
 	}
 	if (mLastWeight != mLastWeight)
 	{
-		mLastWeight = mCurWeight+.001;
+		mLastWeight = mCurWeight+0.001f;
 	}
 
 	// perform differential update of morph
diff --git a/indra/llappearance/llwearable.cpp b/indra/llappearance/llwearable.cpp
index 6079913a8e7..e3565ee4504 100644
--- a/indra/llappearance/llwearable.cpp
+++ b/indra/llappearance/llwearable.cpp
@@ -672,9 +672,10 @@ void LLWearable::addVisualParam(LLVisualParam *param)
 
 void LLWearable::setVisualParamWeight(S32 param_index, F32 value)
 {
-	if( is_in_map(mVisualParamIndexMap, param_index ) )
+	auto iter = mVisualParamIndexMap.find(param_index);
+	if(iter != mVisualParamIndexMap.end())
 	{
-		LLVisualParam *wearable_param = mVisualParamIndexMap[param_index];
+		LLVisualParam *wearable_param = iter->second;
 		wearable_param->setWeight(value);
 	}
 	else
@@ -685,16 +686,17 @@ void LLWearable::setVisualParamWeight(S32 param_index, F32 value)
 
 F32 LLWearable::getVisualParamWeight(S32 param_index) const
 {
-	if( is_in_map(mVisualParamIndexMap, param_index ) )
+	auto iter = mVisualParamIndexMap.find(param_index);
+	if(iter != mVisualParamIndexMap.end())
 	{
-		const LLVisualParam *wearable_param = mVisualParamIndexMap.find(param_index)->second;
+		const LLVisualParam *wearable_param = iter->second;
 		return wearable_param->getWeight();
 	}
 	else
 	{
 		LL_WARNS() << "LLWerable::getVisualParam passed invalid parameter index: "  << param_index << " for wearable type: " << this->getName() << LL_ENDL;
 	}
-	return (F32)-1.0;
+	return (F32)-1.0f;
 }
 
 LLVisualParam* LLWearable::getVisualParam(S32 index) const
@@ -718,11 +720,9 @@ void LLWearable::getVisualParams(visual_param_vec_t &list)
 
 void LLWearable::animateParams(F32 delta)
 {
-	for(visual_param_index_map_t::iterator iter = mVisualParamIndexMap.begin();
-		 iter != mVisualParamIndexMap.end();
-		 ++iter)
+	for(const auto& param_pair : mVisualParamIndexMap)
 	{
-		LLVisualParam *param = (LLVisualParam*) iter->second;
+		LLVisualParam *param = (LLVisualParam*)param_pair.second;
 		param->animate(delta);
 	}
 }
@@ -762,7 +762,8 @@ void LLWearable::writeToAvatar(LLAvatarAppearance* avatarp)
 	{
 		// cross-wearable parameters are not authoritative, as they are driven by a different wearable. So don't copy the values to the
 		// avatar object if cross wearable. Cross wearable params get their values from the avatar, they shouldn't write the other way.
-		if( (((LLViewerVisualParam*)param)->getWearableType() == mType) && (!((LLViewerVisualParam*)param)->getCrossWearable()) )
+		LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
+		if((viewer_param->getWearableType() == mType) && (!viewer_param->getCrossWearable()) )
 		{
 			S32 param_id = param->getID();
 			F32 weight = getVisualParamWeight(param_id);
diff --git a/indra/llcharacter/llpose.cpp b/indra/llcharacter/llpose.cpp
index fc95fafd614..9ce32ebc318 100644
--- a/indra/llcharacter/llpose.cpp
+++ b/indra/llcharacter/llpose.cpp
@@ -478,7 +478,8 @@ BOOL LLPoseBlender::addMotion(LLMotion* motion)
 	{
 		LLJoint *jointp = jsp->getJoint();
 		LLJointStateBlender* joint_blender;
-		if (mJointStateBlenderPool.find(jointp) == mJointStateBlenderPool.end())
+		auto joint_iter = mJointStateBlenderPool.find(jointp);
+		if (joint_iter == mJointStateBlenderPool.end())
 		{
 			// this is the first time we are animating this joint
 			// so create new jointblender and add it to our pool
@@ -487,7 +488,7 @@ BOOL LLPoseBlender::addMotion(LLMotion* motion)
 		}
 		else
 		{
-			joint_blender = mJointStateBlenderPool[jointp];
+			joint_blender = joint_iter->second;
 		}
 
 		if (jsp->getPriority() == LLJoint::USE_MOTION_PRIORITY)
@@ -513,10 +514,8 @@ BOOL LLPoseBlender::addMotion(LLMotion* motion)
 //-----------------------------------------------------------------------------
 void LLPoseBlender::blendAndApply()
 {
-	for (blender_list_t::iterator iter = mActiveBlenders.begin();
-		 iter != mActiveBlenders.end(); )
+	for (LLJointStateBlender* jsbp : mActiveBlenders)
 	{
-		LLJointStateBlender* jsbp = *iter++;
 		jsbp->blendJointStates();
 	}
 
diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp
index 3d28cd15b02..08c3285fdea 100644
--- a/indra/llcommon/llfasttimer.cpp
+++ b/indra/llcommon/llfasttimer.cpp
@@ -222,8 +222,8 @@ void BlockTimer::bootstrapTimerTree()
 // this preserves partial order derived from current frame's observations
 void BlockTimer::incrementalUpdateTimerTree()
 {
-	for(block_timer_tree_df_post_iterator_t it = begin_block_timer_tree_df_post(BlockTimer::getRootTimeBlock());
-		it != end_block_timer_tree_df_post();
+	for(block_timer_tree_df_post_iterator_t it = begin_block_timer_tree_df_post(BlockTimer::getRootTimeBlock()), end = end_block_timer_tree_df_post();
+		it != end;
 		++it)
 	{
 		BlockTimerStatHandle* timerp = *it;
@@ -396,8 +396,8 @@ void BlockTimer::dumpCurTimes()
 	LLTrace::Recording& last_frame_recording = frame_recording.getLastRecording();
 
 	// walk over timers in depth order and output timings
-	for(block_timer_tree_df_iterator_t it = begin_timer_tree(BlockTimer::getRootTimeBlock());
-		it != end_timer_tree();
+	for(block_timer_tree_df_iterator_t it = begin_timer_tree(BlockTimer::getRootTimeBlock()), end = end_timer_tree();
+		it != end;
 		++it)
 	{
 		BlockTimerStatHandle* timerp = (*it);
-- 
GitLab