From 1181180474b1eb4310bfe41cd599d118d2b45d15 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@bred.dog>
Date: Mon, 12 Aug 2019 07:28:03 -0400
Subject: [PATCH] Faster rigged mesh cache...possibly...profiling said so?

---
 indra/newview/lldrawpoolavatar.cpp | 12 ++++++------
 indra/newview/llvoavatar.h         |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp
index e92680f9b4..9fe89a91fe 100644
--- a/indra/newview/lldrawpoolavatar.cpp
+++ b/indra/newview/lldrawpoolavatar.cpp
@@ -1949,14 +1949,14 @@ void LLDrawPoolAvatar::renderRigged(LLVOAvatar* avatar, U32 type, bool glow)
 			if (sShaderLevel > 0)
 			{
 				auto& mesh_cache = avatar->getRiggedMatrixCache();
-				auto& mesh_id = skin->mMeshID;
-				auto rigged_matrix_data_iter = std::find_if(mesh_cache.begin(), mesh_cache.end(), [&mesh_id](const auto& entry) { return entry.first == mesh_id; });
+				const auto& mesh_id = skin->mMeshID;
+				const auto& rigged_matrix_data_iter = mesh_cache.find(mesh_id);
 				if (rigged_matrix_data_iter != mesh_cache.cend() && (!avatar->isSelf() || !avatar->isEditingAppearance()))
 				{
 					LLDrawPoolAvatar::sVertexProgram->uniformMatrix3x4fv(LLViewerShaderMgr::AVATAR_MATRIX,
 						rigged_matrix_data_iter->second.first,
 						FALSE,
-						(GLfloat*) rigged_matrix_data_iter->second.second.data());
+						(GLfloat*)rigged_matrix_data_iter->second.second.data());
 
 					stop_glerror();
 				}
@@ -1969,7 +1969,8 @@ void LLDrawPoolAvatar::renderRigged(LLVOAvatar* avatar, U32 type, bool glow)
 
 					stop_glerror();
 
-					std::array<F32, LL_MAX_JOINTS_PER_MESH_OBJECT * 12> mp;
+					std::vector<F32> mp;
+					mp.reserve(count * 12);
 
 					for (U32 i = 0; i < count; ++i)
 					{
@@ -1992,12 +1993,11 @@ void LLDrawPoolAvatar::renderRigged(LLVOAvatar* avatar, U32 type, bool glow)
 						mp[idx + 10] = m[10];
 						mp[idx + 11] = m[14];
 					}
-					mesh_cache.emplace_back(std::make_pair(skin->mMeshID, std::make_pair(count, mp)));
 					LLDrawPoolAvatar::sVertexProgram->uniformMatrix3x4fv(LLViewerShaderMgr::AVATAR_MATRIX,
 						count,
 						FALSE,
 						(GLfloat*) mp.data());
-
+					mesh_cache.emplace(mesh_id, std::make_pair(count, std::move(mp)));
 					stop_glerror();
 				}
 			}
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 949816b216..8f284f4a57 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -1091,8 +1091,8 @@ protected: // Shared with LLVOAvatarSelf
  *******************************************************************************/
 
 public:
-	typedef std::array<F32, LL_MAX_JOINTS_PER_MESH_OBJECT * 12> rigged_matrix_array_t;
-	typedef std::vector <std::pair< LLUUID, std::pair<U32, rigged_matrix_array_t> > > rigged_transformation_cache_t;
+	typedef std::vector<F32> rigged_matrix_array_t;
+	typedef absl::flat_hash_map<LLUUID, std::pair<U32, rigged_matrix_array_t> > rigged_transformation_cache_t;
 	auto& getRiggedMatrixCache()
 	{
 		return mRiggedMatrixDataCache;
-- 
GitLab