From 7e6ac544f77a701eb7e70b6d21338ad38dc5781a Mon Sep 17 00:00:00 2001 From: joshua stein Date: Mon, 17 Feb 2020 13:19:28 -0600 Subject: [PATCH] AK: Add ptr_hash to use int_hash or u64_hash depending on pointer size --- AK/HashFunctions.h | 8 ++++++++ AK/OwnPtr.h | 2 +- AK/RefPtr.h | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) 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(); } };