diff --git a/AK/HashFunctions.h b/AK/HashFunctions.h index 9fb365c7444..caad086d76a 100644 --- a/AK/HashFunctions.h +++ b/AK/HashFunctions.h @@ -50,3 +50,11 @@ inline unsigned u64_hash(u64 key) u32 last = key >> 32; return pair_int_hash(first, last); } + +inline unsigned ptr_hash(uintptr_t ptr) +{ + if constexpr(sizeof(ptr) == 8) + return u64_hash((u64)ptr); + else + return int_hash((u32)ptr); +} diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 66809382011..b975abd8739 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -204,7 +204,7 @@ inline void swap(OwnPtr& a, OwnPtr& b) template struct Traits> : public GenericTraits> { using PeekType = const T*; - static unsigned hash(const OwnPtr& p) { return int_hash((u32)p.ptr()); } + static unsigned hash(const OwnPtr& p) { return ptr_hash(p.ptr()); } static bool equals(const OwnPtr& a, const OwnPtr& b) { return a.ptr() == b.ptr(); } }; diff --git a/AK/RefPtr.h b/AK/RefPtr.h index c3cd1aa556e..6e5a9554b59 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -278,7 +278,7 @@ inline const LogStream& operator<<(const LogStream& stream, const RefPtr& val template struct Traits> : public GenericTraits> { using PeekType = const T*; - static unsigned hash(const RefPtr& p) { return int_hash((u32)p.ptr()); } + static unsigned hash(const RefPtr& p) { return ptr_hash(p.ptr()); } static bool equals(const RefPtr& a, const RefPtr& b) { return a.ptr() == b.ptr(); } };