From 1eb2b23f4b254052924b198d446c052df9ca3124 Mon Sep 17 00:00:00 2001 From: Henri Beauchamp Date: Tue, 7 Feb 2023 13:51:53 +0100 Subject: SL-19159 Faster LLUUID and LLMaterialID hashing for std and boost containers keys (#70) LLUUID and LLMaterialID already have an excellent entropy and value dispersion; there is therefore strictly no need to further (slowly) hash their value for use with std and boost libraries containers. This commit adds a trivial getDigest64() method to both LLUUID and LLMaterialID (which simply returns the XOR of the two 64 bits long words their value is made of), and uses it in std::hash and hash_value() specializations for use with containers. --- indra/newview/llmaterialmgr.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'indra/newview/llmaterialmgr.h') diff --git a/indra/newview/llmaterialmgr.h b/indra/newview/llmaterialmgr.h index 843dc66fbc..47c322357a 100644 --- a/indra/newview/llmaterialmgr.h +++ b/indra/newview/llmaterialmgr.h @@ -102,13 +102,6 @@ private: (lhs.materialID < rhs.materialID); } - struct TEMaterialPairHasher - { - enum { bucket_size = 8 }; - size_t operator()(const TEMaterialPair& key_value) const { return *((size_t*)key_value.materialID.get()); } // cheesy, but effective - bool operator()(const TEMaterialPair& left, const TEMaterialPair& right) const { return left < right; } - }; - typedef std::set material_queue_t; typedef std::map get_queue_t; typedef std::pair pending_material_t; @@ -116,7 +109,7 @@ private: typedef std::map get_callback_map_t; - typedef boost::unordered_map get_callback_te_map_t; + typedef boost::unordered_map get_callback_te_map_t; typedef std::set getall_queue_t; typedef std::map getall_pending_map_t; typedef std::map getall_callback_map_t; @@ -146,5 +139,23 @@ private: U32 getMaxEntries(const LLViewerRegion* regionp); }; +// std::hash implementation for TEMaterialPair +namespace std +{ + template<> struct hash + { + inline size_t operator()(const LLMaterialMgr::TEMaterialPair& p) const noexcept + { + return size_t((p.te + 1) * p.materialID.getDigest64()); + } + }; +} + +// For use with boost containers. +inline size_t hash_value(const LLMaterialMgr::TEMaterialPair& p) noexcept +{ + return size_t((p.te + 1) * p.materialID.getDigest64()); +} + #endif // LL_LLMATERIALMGR_H -- cgit v1.2.3 From e2496eff18315a82a82e50784c5959dfb038d02f Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 15 Feb 2023 23:42:58 +0200 Subject: SL-19159 Build fixes --- indra/newview/llmaterialmgr.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/llmaterialmgr.h') diff --git a/indra/newview/llmaterialmgr.h b/indra/newview/llmaterialmgr.h index 47c322357a..00b3321737 100644 --- a/indra/newview/llmaterialmgr.h +++ b/indra/newview/llmaterialmgr.h @@ -82,7 +82,7 @@ private: void onPutResponse(bool success, const LLSD& content); void onRegionRemoved(LLViewerRegion* regionp); -private: +public: // struct for TE-specific material ID query class TEMaterialPair { @@ -93,7 +93,8 @@ private: bool operator==(const TEMaterialPair& b) const { return (materialID == b.materialID) && (te == b.te); } }; - + +private: friend inline bool operator<( const LLMaterialMgr::TEMaterialPair& lhs, const LLMaterialMgr::TEMaterialPair& rhs) -- cgit v1.2.3 From 152f32918d15e9343658b728adaf1d5c8c3c3e10 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 15 Feb 2023 16:50:18 -0500 Subject: SL-18330: Fix egregious existing build errors in contribute branch. --- indra/newview/llmaterialmgr.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/newview/llmaterialmgr.h') diff --git a/indra/newview/llmaterialmgr.h b/indra/newview/llmaterialmgr.h index 00b3321737..8f1ec8584b 100644 --- a/indra/newview/llmaterialmgr.h +++ b/indra/newview/llmaterialmgr.h @@ -82,7 +82,7 @@ private: void onPutResponse(bool success, const LLSD& content); void onRegionRemoved(LLViewerRegion* regionp); -public: +private: // struct for TE-specific material ID query class TEMaterialPair { @@ -94,7 +94,10 @@ public: bool operator==(const TEMaterialPair& b) const { return (materialID == b.materialID) && (te == b.te); } }; -private: + // definitions follow class + friend std::hash; + friend size_t hash_value(const TEMaterialPair&) noexcept; + friend inline bool operator<( const LLMaterialMgr::TEMaterialPair& lhs, const LLMaterialMgr::TEMaterialPair& rhs) -- cgit v1.2.3