diff options
author | Henri Beauchamp <sldevel@users.noreply.github.com> | 2023-02-07 13:51:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-07 14:51:53 +0200 |
commit | 1eb2b23f4b254052924b198d446c052df9ca3124 (patch) | |
tree | 0693ffa2dd5bbc83f798cef02bc01d273c943fc3 /indra/newview | |
parent | 61b93e778bf58f6db4d2f3d8dd6ec67de25598ea (diff) |
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.
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llmaterialmgr.h | 27 |
1 files changed, 19 insertions, 8 deletions
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<LLMaterialID> material_queue_t; typedef std::map<LLUUID, material_queue_t> get_queue_t; typedef std::pair<const LLUUID, LLMaterialID> pending_material_t; @@ -116,7 +109,7 @@ private: typedef std::map<LLMaterialID, get_callback_t*> get_callback_map_t; - typedef boost::unordered_map<TEMaterialPair, get_callback_te_t*, TEMaterialPairHasher> get_callback_te_map_t; + typedef boost::unordered_map<TEMaterialPair, get_callback_te_t*> get_callback_te_map_t; typedef std::set<LLUUID> getall_queue_t; typedef std::map<LLUUID, F64> getall_pending_map_t; typedef std::map<LLUUID, getall_callback_t*> getall_callback_map_t; @@ -146,5 +139,23 @@ private: U32 getMaxEntries(const LLViewerRegion* regionp); }; +// std::hash implementation for TEMaterialPair +namespace std +{ + template<> struct hash<LLMaterialMgr::TEMaterialPair> + { + 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 |