From f0b5441034f2ed43202a1f418d8483fa52aef00d Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Wed, 18 Mar 2020 08:26:13 -0400
Subject: [PATCH] Add isInBuddyList to LLVOAvatar for caching friend check to
 reduce map.find

---
 indra/newview/llvoavatar.cpp | 31 ++++++++++++++++++++++++++-----
 indra/newview/llvoavatar.h   |  9 ++++++---
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index dbcdd579b69..940c05d9c19 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1,4 +1,4 @@
-/** 
+/** 
  * @File llvoavatar.cpp
  * @brief Implementation of LLVOAvatar class which is a derivation of LLViewerObject
  *
@@ -676,6 +676,8 @@ LLVOAvatar::LLVOAvatar(const LLUUID& id,
 	mLastUpdateReceivedCOFVersion(-1),
 	mCachedMuteListUpdateTime(0),
 	mCachedInMuteList(false),
+	mCachedBuddyListUpdateTime(0),
+	mCachedInBuddyList(false),
     mIsControlAvatar(false),
     mIsUIAvatar(false),
     mEnableDefaultMotions(true)
@@ -3169,7 +3171,7 @@ void LLVOAvatar::idleUpdateNameTagText(BOOL new_name)
 	}
 //	bool is_friend = LLAvatarTracker::instance().isBuddy(getID());
 // [RLVa:KB] - Checked: RLVa-1.2.2
-	bool is_friend = (fRlvShowAvName) && (LLAvatarTracker::instance().isBuddy(getID()));
+	bool is_friend = (fRlvShowAvName) && isInBuddyList();
 // [/RLVa:KB]
 	bool is_cloud = getIsCloud();
 
@@ -3581,7 +3583,7 @@ bool LLVOAvatar::isVisuallyMuted()
 	return muted;
 }
 
-bool LLVOAvatar::isInMuteList()
+bool LLVOAvatar::isInMuteList() const
 {
 	bool muted = false;
 	F64 now = LLFrameTimer::getTotalSeconds();
@@ -3600,6 +3602,25 @@ bool LLVOAvatar::isInMuteList()
 	return muted;
 }
 
+bool LLVOAvatar::isInBuddyList() const
+{
+	bool is_friend = false;
+	F64 now = LLFrameTimer::getTotalSeconds();
+	if (now < mCachedBuddyListUpdateTime)
+	{
+		is_friend = mCachedInBuddyList;
+	}
+	else
+	{
+		is_friend = LLAvatarTracker::instance().isBuddy(getID());
+
+		const F64 SECONDS_BETWEEN_MUTE_UPDATES = 1;
+		mCachedBuddyListUpdateTime = now + SECONDS_BETWEEN_MUTE_UPDATES;
+		mCachedInBuddyList = is_friend;
+	}
+	return is_friend;
+}
+
 // [RLVa:KB] - Checked: RLVa-2.2 (@setcam_avdist)
 bool LLVOAvatar::isRlvSilhouette()
 {
@@ -7991,7 +8012,7 @@ bool LLVOAvatar::isTooComplex() const
 {
 	static const LLCachedControl<bool> always_render_friends(gSavedSettings, "AlwaysRenderFriends", false);
 	bool too_complex;
-	bool render_friend =  (always_render_friends && LLAvatarTracker::instance().isBuddy(getID()));
+	bool render_friend =  (always_render_friends && isInBuddyList());
 
 	if (isSelf() || render_friend || mVisuallyMuteSetting == AV_ALWAYS_RENDER)
 	{
@@ -10606,7 +10627,7 @@ void LLVOAvatar::calcMutedAVColor()
 		 }
 // [/RLVa:KB]
     }
-    else if (LLMuteList::getInstance()->isMuted(av_id)) // the user blocked them
+    else if (isInMuteList()) // the user blocked them
     {
         // blocked avatars are dark grey
         new_color = LLColor4::grey4;
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 0be915d70eb..932e63809d5 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -426,7 +426,8 @@ class LLVOAvatar :
 public:
 	U32 		renderImpostor(LLColor4U color = LLColor4U(255,255,255,255), S32 diffuse_channel = 0);
 	bool		isVisuallyMuted();
-	bool 		isInMuteList();
+	bool 		isInMuteList() const;
+	bool		isInBuddyList() const;
 // [RLVa:KB] - Checked: RLVa-2.2 (@setcam_avdist)
 	bool        isRlvSilhouette();
 // [/RLVa:KB]
@@ -473,8 +474,10 @@ class LLVOAvatar :
 	mutable bool mVisualComplexityStale;
 	U32          mReportedVisualComplexity; // from other viewers through the simulator
 
-	bool		mCachedInMuteList;
-	F64			mCachedMuteListUpdateTime;
+	mutable bool		mCachedInMuteList;
+	mutable F64			mCachedMuteListUpdateTime;
+	mutable bool		mCachedInBuddyList;
+	mutable F64			mCachedBuddyListUpdateTime;
 // [RLVa:KB] - Checked: RLVa-2.2 (@setcam_avdist)
 	mutable bool mCachedIsRlvSilhouette = false;
 	mutable F64  mCachedRlvSilhouetteUpdateTime = 0.f;
-- 
GitLab