From 148301978977a3b58042540396d52b681af0d315 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 21 Jul 2020 04:29:19 -0400
Subject: [PATCH] Largely replace boost::unordered_map with robin_hood hashmaps

---
 indra/llcommon/llerror.cpp           |  4 ++--
 indra/llcommon/llinitparam.h         |  4 ++--
 indra/llcommon/llpounceable.h        |  4 ++--
 indra/llcommon/llstaticstringtable.h | 14 +++-----------
 indra/llmessage/llavatarnamecache.h  |  8 ++++----
 indra/llrender/llfontfreetype.h      |  6 +++---
 indra/llrender/llgl.cpp              |  9 ++++-----
 indra/llrender/llgl.h                |  4 ++--
 indra/llrender/llglslshader.h        |  2 ++
 indra/newview/llmaterialmgr.h        |  2 ++
 indra/newview/llviewermenu.cpp       |  4 ++--
 indra/newview/llviewerobjectlist.cpp |  4 ++--
 indra/newview/llviewerobjectlist.h   |  6 +++---
 13 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp
index 6a332054475..9a6124b504a 100644
--- a/indra/llcommon/llerror.cpp
+++ b/indra/llcommon/llerror.cpp
@@ -44,7 +44,7 @@
 # include <io.h>
 #endif // !LL_WINDOWS
 #include <vector>
-#include <boost/unordered_map.hpp>
+#include <robin_hood.h>
 #include "string.h"
 
 #include "llapp.h"
@@ -498,7 +498,7 @@ namespace LLError
 		LevelMap                            mClassLevelMap;
 		LevelMap                            mFileLevelMap;
 		LevelMap                            mTagLevelMap;
-		boost::unordered_map<std::string, unsigned int> mUniqueLogMessages;
+		robin_hood::unordered_map<std::string, unsigned int> mUniqueLogMessages;
 		
 		LLError::FatalFunction              mCrashFunction;
 		LLError::TimeFunction               mTimeFunction;
diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h
index 7f5b9b4ac23..9610562a210 100644
--- a/indra/llcommon/llinitparam.h
+++ b/indra/llcommon/llinitparam.h
@@ -34,7 +34,7 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/type_traits/is_convertible.hpp>
 #include <boost/type_traits/is_enum.hpp>
-#include <boost/unordered_map.hpp>
+#include <robin_hood.h>
 
 #include "llerror.h"
 #include "llstl.h"
@@ -649,7 +649,7 @@ namespace LLInitParam
 		void aggregateBlockData(BlockDescriptor& src_block_data);
 		void addParam(ParamDescriptorPtr param, const char* name);
 
-		typedef boost::unordered_map<const std::string, ParamDescriptorPtr>						param_map_t; 
+		typedef robin_hood::unordered_node_map<std::string, ParamDescriptorPtr>						param_map_t; 
 		typedef std::vector<ParamDescriptorPtr>													param_list_t; 
 		typedef std::list<ParamDescriptorPtr>													all_params_list_t;
 		typedef std::vector<std::pair<param_handle_t, ParamDescriptor::validation_func_t> >		param_validation_list_t;
diff --git a/indra/llcommon/llpounceable.h b/indra/llcommon/llpounceable.h
index 0421ce966a7..4d5f841f523 100644
--- a/indra/llcommon/llpounceable.h
+++ b/indra/llcommon/llpounceable.h
@@ -40,8 +40,8 @@
 #include <boost/call_traits.hpp>
 #include <boost/type_traits/remove_pointer.hpp>
 #include <boost/utility/value_init.hpp>
-#include <boost/unordered_map.hpp>
 #include <boost/signals2/signal.hpp>
+#include <robin_hood.h>
 
 // Forward declare the user template, since we want to be able to point to it
 // in some of its implementation classes.
@@ -86,7 +86,7 @@ class LLPounceableQueueSingleton:
     // instance will call on the SAME LLPounceableQueueSingleton instance --
     // given how class statics work. We must keep a separate queue for each
     // LLPounceable instance. Use a hash map for that.
-    typedef boost::unordered_map<owner_ptr, signal_t> map_t;
+    typedef robin_hood::unordered_node_map<owner_ptr, signal_t> map_t;
 
 public:
     // Disambiguate queues belonging to different LLPounceables.
diff --git a/indra/llcommon/llstaticstringtable.h b/indra/llcommon/llstaticstringtable.h
index d7e0e8a08df..0cc77824d1c 100644
--- a/indra/llcommon/llstaticstringtable.h
+++ b/indra/llcommon/llstaticstringtable.h
@@ -29,7 +29,7 @@
 #define LL_STATIC_STRING_TABLE_H
 
 #include "lldefs.h"
-#include <boost/unordered_map.hpp>
+#include <robin_hood.h>
 #include "llstl.h"
 
 class LLStaticHashedString
@@ -51,14 +51,7 @@ class LLStaticHashedString
 
 	size_t makehash(const std::string& s)
 	{
-		size_t len = s.size();
-		const char* c = s.c_str();
-		size_t hashval = 0;
-		for (size_t i=0; i<len; i++)
-		{
-			hashval = ((hashval<<5) + hashval) + *c++;
-		}
-		return hashval;
+		return robin_hood::hash<std::string>{}(s);
 	}
 
 	std::string string;
@@ -67,14 +60,13 @@ class LLStaticHashedString
 
 struct LLStaticStringHasher
 {
-	enum { bucket_size = 8 };
 	size_t operator()(const LLStaticHashedString& key_value) const { return key_value.Hash(); }
 	bool   operator()(const LLStaticHashedString& left, const LLStaticHashedString& right) const { return left.Hash() < right.Hash(); }
 };
 
 template< typename MappedObject >
 class LL_COMMON_API LLStaticStringTable
-	: public boost::unordered_map< LLStaticHashedString, MappedObject, LLStaticStringHasher >
+	: public robin_hood::unordered_map< LLStaticHashedString, MappedObject, LLStaticStringHasher >
 {
 };
 
diff --git a/indra/llmessage/llavatarnamecache.h b/indra/llmessage/llavatarnamecache.h
index 70466d9c40f..ecbb5820aa6 100644
--- a/indra/llmessage/llavatarnamecache.h
+++ b/indra/llmessage/llavatarnamecache.h
@@ -32,7 +32,7 @@
 #include "llavatarname.h"	// for convenience
 #include "llsingleton.h"
 #include <boost/signals2.hpp>
-#include <boost/unordered_map.hpp>
+#include <robin_hood.h>
 #include <set>
 
 class LLSD;
@@ -174,18 +174,18 @@ class LLAvatarNameCache : public LLSingleton<LLAvatarNameCache>
 
     // Agent IDs that have been requested, but with no reply.
     // Maps agent ID to frame time request was made.
-    typedef boost::unordered_map<LLUUID, F64> pending_queue_t;
+    typedef robin_hood::unordered_map<LLUUID, F64> pending_queue_t;
     pending_queue_t mPendingQueue;
 
     // Callbacks to fire when we received a name.
     // May have multiple callbacks for a single ID, which are
     // represented as multiple slots bound to the signal.
     // Avoid copying signals via pointers.
-    typedef boost::unordered_map<LLUUID, callback_signal_t*> signal_map_t;
+    typedef robin_hood::unordered_map<LLUUID, callback_signal_t*> signal_map_t;
     signal_map_t mSignalMap;
 
     // The cache at last, i.e. avatar names we know about.
-    typedef boost::unordered_map<LLUUID, LLAvatarName> cache_t;
+    typedef robin_hood::unordered_node_map<LLUUID, LLAvatarName> cache_t;
     cache_t mCache;
 
     // Time when unrefreshed cached names were checked last.
diff --git a/indra/llrender/llfontfreetype.h b/indra/llrender/llfontfreetype.h
index 9bf0c1480fc..b692238c5e9 100644
--- a/indra/llrender/llfontfreetype.h
+++ b/indra/llrender/llfontfreetype.h
@@ -27,7 +27,7 @@
 #ifndef LL_LLFONTFREETYPE_H
 #define LL_LLFONTFREETYPE_H
 
-#include <boost/unordered_map.hpp>
+#include <robin_hood.h>
 #include "llpointer.h"
 #include "llstl.h"
 
@@ -160,7 +160,7 @@ class LLFontFreetype final : public LLRefCount, public LLTrace::MemTrackable<LLF
 	bool getKerningCache(U32 left_glyph, U32 right_glyph, F32& kerning) const;
 	void setKerningCache(U32 left_glyph, U32 right_glyph, F32 kerning) const;
 
-	mutable boost::unordered_map<U64, F32> mKerningCache;
+	mutable robin_hood::unordered_map<U64, F32> mKerningCache;
 
 	std::string mName;
 
@@ -181,7 +181,7 @@ class LLFontFreetype final : public LLRefCount, public LLTrace::MemTrackable<LLF
 	BOOL mIsFallback;
 	font_vector_t mFallbackFonts; // A list of fallback fonts to look for glyphs in (for Unicode chars)
 
-	typedef boost::unordered_map<llwchar, LLFontGlyphInfo*> char_glyph_info_map_t;
+	typedef robin_hood::unordered_map<llwchar, LLFontGlyphInfo*> char_glyph_info_map_t;
 	mutable char_glyph_info_map_t mCharGlyphInfoMap; // Information about glyph location in bitmap
 
 	mutable LLFontBitmapCache* mFontBitmapCachep;
diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp
index ce429c0369a..4b8762d0ace 100644
--- a/indra/llrender/llgl.cpp
+++ b/indra/llrender/llgl.cpp
@@ -1644,7 +1644,7 @@ void clear_glerror()
 //
 
 // Static members
-boost::unordered_map<LLGLenum, LLGLboolean> LLGLState::sStateMap;
+robin_hood::unordered_map<LLGLenum, LLGLboolean> LLGLState::sStateMap;
 
 GLboolean LLGLDepthTest::sDepthEnabled = GL_FALSE; // OpenGL default
 GLenum LLGLDepthTest::sDepthFunc = GL_LESS; // OpenGL default
@@ -1687,10 +1687,9 @@ void LLGLState::resetTextureStates()
 void LLGLState::dumpStates() 
 {
 	LL_INFOS("RenderState") << "GL States:" << LL_ENDL;
-	for (boost::unordered_map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin();
-		 iter != sStateMap.end(); ++iter)
+	for (const auto& state_pair : sStateMap)
 	{
-		LL_INFOS("RenderState") << llformat(" 0x%04x : %s",(S32)iter->first,iter->second?"TRUE":"FALSE") << LL_ENDL;
+		LL_INFOS("RenderState") << llformat(" 0x%04x : %s",(S32)state_pair.first, state_pair.second?"TRUE":"FALSE") << LL_ENDL;
 	}
 }
 
@@ -1725,7 +1724,7 @@ void LLGLState::checkStates(const std::string& msg)
 		}
 	}
 	
-	for (boost::unordered_map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin();
+	for (auto iter = sStateMap.begin();
 		 iter != sStateMap.end(); ++iter)
 	{
 		LLGLenum state = iter->first;
diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h
index 1ee2389be5f..e3e9ef39373 100644
--- a/indra/llrender/llgl.h
+++ b/indra/llrender/llgl.h
@@ -30,7 +30,7 @@
 // This file contains various stuff for handling gl extensions and other gl related stuff.
 
 #include <string>
-#include <boost/unordered_map.hpp>
+#include <robin_hood.h>
 #include <list>
 
 #include "llerror.h"
@@ -274,7 +274,7 @@ class LLGLState
 	static void checkClientArrays(const std::string& msg = "", U32 data_mask = 0);
 	
 protected:
-	static boost::unordered_map<LLGLenum, LLGLboolean> sStateMap;
+	static robin_hood::unordered_map<LLGLenum, LLGLboolean> sStateMap;
 	
 public:
 	enum { CURRENT_STATE = -2 };
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index 7cf6d3c941f..c295d33a8f0 100644
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -31,6 +31,8 @@
 #include "llrender.h"
 #include "llstaticstringtable.h"
 
+#include <boost/unordered_map.hpp>
+
 class LLShaderFeatures
 {
 public:
diff --git a/indra/newview/llmaterialmgr.h b/indra/newview/llmaterialmgr.h
index 843dc66fbca..31e7fa19170 100644
--- a/indra/newview/llmaterialmgr.h
+++ b/indra/newview/llmaterialmgr.h
@@ -34,6 +34,8 @@
 #include "httpheaders.h"
 #include "httpoptions.h"
 
+#include <boost/unordered_map.hpp>
+
 class LLViewerRegion;
 
 class LLMaterialMgr : public LLSingleton<LLMaterialMgr>
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index b629b9f1e9f..dfccc2ba164 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -148,7 +148,7 @@ using namespace LLAvatarAppearanceDefines;
 
 typedef LLPointer<LLViewerObject> LLViewerObjectPtr;
 
-static boost::unordered_map<std::string, LLStringExplicit> sDefaultItemLabels;
+static robin_hood::unordered_map<std::string, LLStringExplicit> sDefaultItemLabels;
 
 BOOL enable_land_build(void*);
 BOOL enable_object_build(void*);
@@ -2706,7 +2706,7 @@ static void init_default_item_label(LLUICtrl* ctrl, const std::string& item_name
 		LLStringExplicit default_label = ctrl->getValue().asString();
 		if (!default_label.empty())
 		{
-			sDefaultItemLabels.insert(std::pair<std::string, LLStringExplicit>(item_name, default_label));
+			sDefaultItemLabels.emplace(item_name, default_label);
 		}
 	}
 }
diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp
index d46d54ee2b7..c7c5b6534a8 100644
--- a/indra/newview/llviewerobjectlist.cpp
+++ b/indra/newview/llviewerobjectlist.cpp
@@ -98,8 +98,8 @@ extern LLPipeline	gPipeline;
 
 // Statics for object lookup tables.
 U32						LLViewerObjectList::sSimulatorMachineIndex = 1; // Not zero deliberately, to speed up index check.
-boost::unordered_map<U64, U32>		LLViewerObjectList::sIPAndPortToIndex;
-boost::unordered_map<U64, LLUUID>	LLViewerObjectList::sIndexAndLocalIDToUUID;
+robin_hood::unordered_map<U64, U32>		LLViewerObjectList::sIPAndPortToIndex;
+robin_hood::unordered_node_map<U64, LLUUID>	LLViewerObjectList::sIndexAndLocalIDToUUID;
 
 LLViewerObjectList::LLViewerObjectList()
 {
diff --git a/indra/newview/llviewerobjectlist.h b/indra/newview/llviewerobjectlist.h
index 9f775ef6ac1..2a3016b1cea 100644
--- a/indra/newview/llviewerobjectlist.h
+++ b/indra/newview/llviewerobjectlist.h
@@ -213,7 +213,7 @@ class LLViewerObjectList
 
     uuid_set_t   mDeadObjects;
 
-	boost::unordered_map<LLUUID, LLPointer<LLViewerObject> > mUUIDObjectMap;
+	robin_hood::unordered_map<LLUUID, LLPointer<LLViewerObject> > mUUIDObjectMap;
 
 	//set of objects that need to update their cost
     uuid_set_t   mStaleObjectCost;
@@ -228,9 +228,9 @@ class LLViewerObjectList
 	S32 mCurLazyUpdateIndex;
 
 	static U32 sSimulatorMachineIndex;
-	static boost::unordered_map<U64, U32> sIPAndPortToIndex;
+	static robin_hood::unordered_map<U64, U32> sIPAndPortToIndex;
 
-	static boost::unordered_map<U64, LLUUID> sIndexAndLocalIDToUUID;
+	static robin_hood::unordered_node_map<U64, LLUUID> sIndexAndLocalIDToUUID;
 
 	std::set<LLViewerObject *> mSelectPickList;
 
-- 
GitLab