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/llcommon/lluuid.h | 50 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'indra/llcommon/lluuid.h') diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h index 86a396ab06..2c36a1d222 100644 --- a/indra/llcommon/lluuid.h +++ b/indra/llcommon/lluuid.h @@ -119,6 +119,14 @@ public: U16 getCRC16() const; U32 getCRC32() const; + // Returns a 64 bits digest of the UUID, by XORing its two 64 bits long + // words. HB + inline U64 getDigest64() const + { + U64* tmp = (U64*)mData; + return tmp[0] ^ tmp[1]; + } + static BOOL validate(const std::string& in_string); // Validate that the UUID string is legal. static const LLUUID null; @@ -165,36 +173,20 @@ public: LLAssetID makeAssetID(const LLUUID& session) const; }; -// Generate a hash of an LLUUID object using the boost hash templates. -template <> -struct boost::hash -{ - typedef LLUUID argument_type; - typedef std::size_t result_type; - result_type operator()(argument_type const& s) const - { - result_type seed(0); - - for (S32 i = 0; i < UUID_BYTES; ++i) - { - boost::hash_combine(seed, s.mData[i]); - } - - return seed; - } -}; - -// Adapt boost hash to std hash +// std::hash implementation for LLUUID namespace std { - template<> struct hash - { - std::size_t operator()(LLUUID const& s) const noexcept - { - return boost::hash()(s); - } - }; + template<> struct hash + { + inline size_t operator()(const LLUUID& id) const noexcept + { + return (size_t)id.getDigest64(); + } + }; } -#endif - +// For use with boost containers. +inline size_t hash_value(const LLUUID& id) noexcept +{ + return (size_t)id.getDigest64(); +} -- 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/llcommon/lluuid.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llcommon/lluuid.h') diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h index 2c36a1d222..cc36797bc1 100644 --- a/indra/llcommon/lluuid.h +++ b/indra/llcommon/lluuid.h @@ -190,3 +190,5 @@ inline size_t hash_value(const LLUUID& id) noexcept { return (size_t)id.getDigest64(); } + +#endif -- 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/llcommon/lluuid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/lluuid.h') diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h index cc36797bc1..0d4896ee97 100644 --- a/indra/llcommon/lluuid.h +++ b/indra/llcommon/lluuid.h @@ -191,4 +191,4 @@ inline size_t hash_value(const LLUUID& id) noexcept return (size_t)id.getDigest64(); } -#endif +#endif // LL_LLUUID_H -- cgit v1.2.3