[clang] [Serialization] Use specialized decl hash function for GlobalDeclID (PR #95730)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 17 02:59:19 PDT 2024


================
@@ -230,7 +230,11 @@ template <> struct DenseMapInfo<clang::GlobalDeclID> {
   }
 
   static unsigned getHashValue(const GlobalDeclID &Key) {
-    return DenseMapInfo<DeclID>::getHashValue(Key.get());
+    // Our default hash algorithm for 64 bits integer may not be very good.
+    // In GlobalDeclID's case, it is pretty common that the lower 32 bits can
+    // be same.
+    return DenseMapInfo<uint32_t>::getHashValue(Key.getModuleFileIndex()) ^
----------------
ilya-biryukov wrote:

+1 to using `hash_combine`, it should provide better results than xor.

https://github.com/llvm/llvm-project/pull/95730


More information about the cfe-commits mailing list