From 9e7cfa37b4216072bf22388c6bddcea8a8390d0c Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Thu, 12 Mar 2020 09:55:52 -0400
Subject: [PATCH] Cache some frequent avatar setting lookups in LLCachedControl

---
 indra/newview/llcontrolavatar.cpp | 24 +++++++++---------------
 indra/newview/llphysicsmotion.cpp |  3 ++-
 indra/newview/llvoavatar.cpp      | 25 +++++++++++++------------
 3 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/indra/newview/llcontrolavatar.cpp b/indra/newview/llcontrolavatar.cpp
index 1f4abdd8edd..7e679d61088 100644
--- a/indra/newview/llcontrolavatar.cpp
+++ b/indra/newview/llcontrolavatar.cpp
@@ -80,19 +80,12 @@ void LLControlAvatar::initInstance()
 
 void LLControlAvatar::getNewConstraintFixups(LLVector3& new_pos_fixup, F32& new_scale_fixup) const
 {
-
-    F32 max_legal_offset = MAX_LEGAL_OFFSET;
-    if (gSavedSettings.getControl("AnimatedObjectsMaxLegalOffset"))
-    {
-        max_legal_offset = gSavedSettings.getF32("AnimatedObjectsMaxLegalOffset");
-    }
+    static const LLCachedControl<F32> max_legal_offset_cc(gSavedSettings, "AnimatedObjectsMaxLegalOffset", MAX_LEGAL_OFFSET);
+    F32 max_legal_offset = max_legal_offset_cc;
 	max_legal_offset = llmax(max_legal_offset,0.f);
 
-    F32 max_legal_size = MAX_LEGAL_SIZE;
-    if (gSavedSettings.getControl("AnimatedObjectsMaxLegalSize"))
-    {
-        max_legal_size = gSavedSettings.getF32("AnimatedObjectsMaxLegalSize");
-    }
+    static const LLCachedControl<F32> max_legal_size_cc(gSavedSettings, "AnimatedObjectsMaxLegalSize", MAX_LEGAL_SIZE);
+    F32 max_legal_size = max_legal_size_cc;
 	max_legal_size = llmax(max_legal_size, 1.f);
     
     new_pos_fixup = LLVector3();
@@ -163,6 +156,8 @@ void LLControlAvatar::matchVolumeTransform()
 		mPositionConstraintFixup = new_pos_fixup;
 		mScaleConstraintFixup = new_scale_fixup;
 
+        static const LLCachedControl<F32> global_scale(gSavedSettings, "AnimatedObjectsGlobalScale");
+
         if (mRootVolp->isAttachment())
         {
             LLVOAvatar *attached_av = mRootVolp->getAvatarAncestor();
@@ -183,7 +178,6 @@ void LLControlAvatar::matchVolumeTransform()
                 mRoot->setWorldRotation(obj_rot * joint_rot);
                 setRotation(mRoot->getRotation());
 
-				F32 global_scale = gSavedSettings.getF32("AnimatedObjectsGlobalScale");
 				setGlobalScale(global_scale * mScaleConstraintFixup);
             }
             else
@@ -234,8 +228,7 @@ void LLControlAvatar::matchVolumeTransform()
             }
 			mRoot->setPosition(vol_pos + mPositionConstraintFixup);
 
-            F32 global_scale = gSavedSettings.getF32("AnimatedObjectsGlobalScale");
-            setGlobalScale(global_scale * mScaleConstraintFixup);
+             setGlobalScale(global_scale * mScaleConstraintFixup);
         }
     }
 }
@@ -368,7 +361,8 @@ BOOL LLControlAvatar::updateCharacter(LLAgent &agent)
 //virtual
 void LLControlAvatar::updateDebugText()
 {
-	if (gSavedSettings.getBOOL("DebugAnimatedObjects"))
+    static const LLCachedControl<bool> debug_anim_obj(gSavedSettings, "DebugAnimatedObjects");
+	if (debug_anim_obj)
     {
         S32 total_linkset_count = 0;
         if (mRootVolp)
diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp
index f48ce680fd1..89382d66fd1 100644
--- a/indra/newview/llphysicsmotion.cpp
+++ b/indra/newview/llphysicsmotion.cpp
@@ -454,7 +454,8 @@ F32 LLPhysicsMotion::calculateAcceleration_local(const F32 velocity_local, const
 BOOL LLPhysicsMotionController::onUpdate(F32 time, U8* joint_mask)
 {
         // Skip if disabled globally.
-        if (!gSavedSettings.getBOOL("AvatarPhysics"))
+    static const LLCachedControl<bool> av_physics(gSavedSettings, "AvatarPhysics");
+        if (!av_physics)
         {
                 return TRUE;
         }
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index aae782667b3..efa25bfb3ce 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1318,7 +1318,7 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
 {
     LL_RECORD_BLOCK_TIME(FTM_AVATAR_EXTENT_UPDATE);
 
-    S32 box_detail = gSavedSettings.getS32("AvatarBoundingBoxComplexity");
+    static const LLCachedControl<S32> box_detail(gSavedSettings, "AvatarBoundingBoxComplexity");
 
     // FIXME the update_min_max function used below assumes there is a
     // known starting point, but in general there isn't. Ideally the
@@ -1377,12 +1377,9 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
 
 		if (attachment->getValid())
 		{
-			for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
-				 attachment_iter != attachment->mAttachedObjects.end();
-				 ++attachment_iter)
+			for (LLViewerObject* attached_object : attachment->mAttachedObjects)
 			{
-                    // Don't we need to look at children of attached_object as well?
-                LLViewerObject* attached_object = attachment_iter->get();
+                // 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();
@@ -3027,8 +3024,8 @@ void LLVOAvatar::idleUpdateNameTag(const LLVector3& root_pos_last)
 	}
 	
 	const F32 time_visible = mTimeVisible.getElapsedTimeF32();
-	const F32 NAME_SHOW_TIME = gSavedSettings.getF32("RenderNameShowTime");	// seconds
-	const F32 FADE_DURATION = gSavedSettings.getF32("RenderNameFadeDuration"); // seconds
+	static const LLCachedControl<F32> NAME_SHOW_TIME(gSavedSettings, "RenderNameShowTime");	// seconds
+	static const LLCachedControl<F32> FADE_DURATION(gSavedSettings, "RenderNameFadeDuration"); // seconds
 // [RLVa:KB] - Checked: RLVa-2.0.1
 	bool fRlvShowAvTag = true, fRlvShowAvName = true;
 	if (RlvActions::isRlvEnabled())
@@ -3038,7 +3035,8 @@ void LLVOAvatar::idleUpdateNameTag(const LLVector3& root_pos_last)
 	}
 // [/RLVa:KB]
 	BOOL visible_avatar = isVisible() || mNeedsAnimUpdate;
-	BOOL visible_chat = gSavedSettings.getBOOL("UseChatBubbles") && (mChats.size() || mTyping);
+	static const LLCachedControl<bool> use_chat_bubble(gSavedSettings, "UseChatBubbles"); // seconds
+	BOOL visible_chat = use_chat_bubble && (mChats.size() || mTyping);
 	BOOL render_name =	visible_chat ||
 		                (visible_avatar &&
 // [RLVa:KB] - Checked: RLVa-2.0.1
@@ -3823,12 +3821,14 @@ void LLVOAvatar::updateDebugText()
 {
     // Leave mDebugText uncleared here, in case a derived class has added some state first
 
-	if (gSavedSettings.getBOOL("DebugAvatarAppearanceMessage"))
+	static const LLCachedControl<bool> debug_av_appr_msg(gSavedSettings, "DebugAvatarAppearanceMessage");
+	if (debug_av_appr_msg)
 	{
         updateAppearanceMessageDebugText();
 	}
 
-	if (gSavedSettings.getBOOL("DebugAvatarCompositeBaked"))
+	static const LLCachedControl<bool> debug_av_comp_bk(gSavedSettings, "DebugAvatarCompositeBaked");
+	if (debug_av_comp_bk)
 	{
 		if (!mBakedTextureDebugText.empty())
 			addDebugText(mBakedTextureDebugText);
@@ -8024,7 +8024,8 @@ LLMotion* LLVOAvatar::findMotion(const LLUUID& id) const
 // colorized if using deferred rendering.
 void LLVOAvatar::debugColorizeSubMeshes(U32 i, const LLColor4& color)
 {
-	if (gSavedSettings.getBOOL("DebugAvatarCompositeBaked"))
+	static const LLCachedControl<bool> debug_av_comp_bk(gSavedSettings, "DebugAvatarCompositeBaked");
+	if (debug_av_comp_bk)
 	{
 		avatar_joint_mesh_list_t::iterator iter = mBakedTextureDatas[i].mJointMeshes.begin();
 		avatar_joint_mesh_list_t::iterator end  = mBakedTextureDatas[i].mJointMeshes.end();
-- 
GitLab