From 0cfdd94567e70e17592f83e653f1df937a35d565 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 26 Sep 2020 02:20:58 -0400
Subject: [PATCH] More performance work around LLUI and color getting

---
 indra/llui/llbutton.cpp           |  2 +-
 indra/llui/llfloater.cpp          |  4 ++--
 indra/llxml/llcontrol.h           |  2 +-
 indra/newview/llmanip.cpp         |  6 +++---
 indra/newview/lloutfitgallery.cpp |  6 ++++--
 indra/newview/llspeakers.cpp      |  4 ++--
 indra/newview/llvoavatar.cpp      | 26 ++++++++++++++++++++------
 7 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp
index c8af7447dd4..9807f1baa82 100644
--- a/indra/llui/llbutton.cpp
+++ b/indra/llui/llbutton.cpp
@@ -627,7 +627,7 @@ void LLButton::getOverlayImageSize(S32& overlay_width, S32& overlay_height)
 // virtual
 void LLButton::draw()
 {
-	static LLCachedControl<bool> sEnableButtonFlashing(*LLUI::getInstance()->mSettingGroups["config"], "EnableButtonFlashing", true);
+	static const LLUICachedControl<bool> sEnableButtonFlashing("EnableButtonFlashing", true);
 	F32 alpha = mUseDrawContextAlpha ? getDrawContext().mAlpha : getCurrentTransparency();
 
 	bool pressed_by_keyboard = FALSE;
diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp
index 1816cb8e1a7..c336966f229 100644
--- a/indra/llui/llfloater.cpp
+++ b/indra/llui/llfloater.cpp
@@ -384,14 +384,14 @@ void LLFloater::layoutDragHandle()
 // static
 void LLFloater::updateActiveFloaterTransparency()
 {
-    static LLCachedControl<F32> active_transparency(*LLUI::getInstance()->mSettingGroups["config"], "ActiveFloaterTransparency", 1.f);
+    static LLUICachedControl<F32> active_transparency("ActiveFloaterTransparency", 1.f);
     sActiveControlTransparency = active_transparency;
 }
 
 // static
 void LLFloater::updateInactiveFloaterTransparency()
 {
-    static LLCachedControl<F32> inactive_transparency(*LLUI::getInstance()->mSettingGroups["config"], "InactiveFloaterTransparency", 0.95f);
+    static LLUICachedControl<F32> inactive_transparency("InactiveFloaterTransparency", 0.95f);
     sInactiveControlTransparency = inactive_transparency;
 }
 
diff --git a/indra/llxml/llcontrol.h b/indra/llxml/llcontrol.h
index ffe3fba72f7..c26a0195b50 100644
--- a/indra/llxml/llcontrol.h
+++ b/indra/llxml/llcontrol.h
@@ -433,7 +433,7 @@ class LLCachedControl
 
 	operator const T&() const { return mCachedControlPtr->getValue(); }
 	operator boost::function<const T&()> () const { return boost::function<const T&()>(*this); }
-	const T& operator()() { return mCachedControlPtr->getValue(); }
+	const T& operator()() const { return mCachedControlPtr->getValue(); }
 
 private:
 	LLPointer<LLControlCache<T> > mCachedControlPtr;
diff --git a/indra/newview/llmanip.cpp b/indra/newview/llmanip.cpp
index 5978e697c84..8c6ec08d660 100644
--- a/indra/newview/llmanip.cpp
+++ b/indra/newview/llmanip.cpp
@@ -585,9 +585,9 @@ void LLManip::renderTickValue(const LLVector3& pos, F32 value, const std::string
 
 LLColor4 LLManip::setupSnapGuideRenderPass(S32 pass)
 {
-	static LLColor4 grid_color_fg = LLUIColorTable::instance().getColor("GridlineColor");
-	static LLColor4 grid_color_bg = LLUIColorTable::instance().getColor("GridlineBGColor");
-	static LLColor4 grid_color_shadow = LLUIColorTable::instance().getColor("GridlineShadowColor");
+	static LLUIColor grid_color_fg = LLUIColorTable::instance().getColor("GridlineColor");
+	static LLUIColor grid_color_bg = LLUIColorTable::instance().getColor("GridlineBGColor");
+	static LLUIColor grid_color_shadow = LLUIColorTable::instance().getColor("GridlineShadowColor");
 
 	LLColor4 line_color;
 	F32 line_alpha = ALControlCache::GridOpacity;
diff --git a/indra/newview/lloutfitgallery.cpp b/indra/newview/lloutfitgallery.cpp
index 50afb4dd569..35b77d9c3e4 100644
--- a/indra/newview/lloutfitgallery.cpp
+++ b/indra/newview/lloutfitgallery.cpp
@@ -690,10 +690,12 @@ void LLOutfitGalleryItem::draw()
     LLPanel::draw();
     
     // Draw border
-    LLUIColor border_color = LLUIColorTable::instance().getColor(mSelected ? "OutfitGalleryItemSelected" : "OutfitGalleryItemUnselected", LLColor4::white);
+    static LLUIColor selected_color = LLUIColorTable::instance().getColor("OutfitGalleryItemSelected", LLColor4::white);
+    static LLUIColor unselected_color = LLUIColorTable::instance().getColor("OutfitGalleryItemUnselected", LLColor4::white);
+    const LLColor4& border_color = mSelected ? selected_color : unselected_color;
     LLRect border = getChildView("preview_outfit")->getRect();
     border.mRight = border.mRight + 1;
-    gl_rect_2d(border, border_color.get(), FALSE);
+    gl_rect_2d(border, border_color, FALSE);
 
     // If the floater is focused, don't apply its alpha to the texture (STORM-677).
     const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
diff --git a/indra/newview/llspeakers.cpp b/indra/newview/llspeakers.cpp
index 8188adad295..7d0afaebed0 100644
--- a/indra/newview/llspeakers.cpp
+++ b/indra/newview/llspeakers.cpp
@@ -364,8 +364,8 @@ void LLSpeakerMgr::update(BOOL resort_ok)
 		return;
 	}
 	
-	LLColor4 speaking_color = LLUIColorTable::instance().getColor("SpeakingColor");
-	LLColor4 overdriven_color = LLUIColorTable::instance().getColor("OverdrivenColor");
+	static const LLUIColor speaking_color = LLUIColorTable::instance().getColor("SpeakingColor");
+	static const LLUIColor overdriven_color = LLUIColorTable::instance().getColor("OverdrivenColor");
 
 	if(resort_ok) // only allow list changes when user is not interacting with it
 	{
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index f8270be7394..0742c682db8 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -3546,11 +3546,25 @@ void LLVOAvatar::idleUpdateNameTagAlpha(BOOL new_name, F32 alpha)
 
 LLColor4 LLVOAvatar::getNameTagColor(bool is_friend)
 {
+	enum ENameColor { NameTagFriend = 0, NameTagMatch, NameTagMismatch, NameTagLegacy, Size};
+	static std::vector<LLUIColor> sNameTagColors;
+	if (sNameTagColors.empty())
+	{
+		sNameTagColors.reserve(ENameColor::Size);
+
+		auto& inst = LLUIColorTable::instance();
+		sNameTagColors[NameTagFriend] = inst.getColor("NameTagFriend");
+		sNameTagColors[NameTagMatch] = inst.getColor("NameTagMatch");
+		sNameTagColors[NameTagMismatch] = inst.getColor("NameTagMismatch");
+		sNameTagColors[NameTagLegacy] = inst.getColor("NameTagLegacy");
+	}
+
 	static LLUICachedControl<bool> show_friends("NameTagShowFriends", false);
-	const char* color_name;
+	ENameColor color_name;
 	if (show_friends && is_friend)
 	{
-		color_name = "NameTagFriend";
+
+		color_name = ENameColor::NameTagFriend;
 	}
 	else if (LLAvatarName::useDisplayNames())
 	{
@@ -3558,19 +3572,19 @@ LLColor4 LLVOAvatar::getNameTagColor(bool is_friend)
 		LLAvatarName av_name;
 		if (LLAvatarNameCache::get(getID(), &av_name) && av_name.isDisplayNameDefault())
 		{
-			color_name = "NameTagMatch";
+			color_name = ENameColor::NameTagMatch;
 		}
 		else
 		{
-			color_name = "NameTagMismatch";
+			color_name = ENameColor::NameTagMismatch;
 		}
 	}
 	else
 	{
 		// ...not using display names
-		color_name = "NameTagLegacy";
+		color_name = ENameColor::NameTagLegacy;
 	}
-	return LLUIColorTable::getInstance()->getColor( color_name );
+	return sNameTagColors[color_name];
 }
 
 void LLVOAvatar::idleUpdateBelowWater()
-- 
GitLab