From c68609b27f571ca00327ef1a1b26da0413f5712b Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sat, 29 Jan 2022 20:15:26 +0200 Subject: [PATCH] Kernel: Make {Nonnull,}OwnPtr hash compatible with StringView This will allow us to use KString as HashTable/HashMap keys more easily --- Kernel/KString.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Kernel/KString.h b/Kernel/KString.h index 7f2b2b3d9c..bc2beef1bc 100644 --- a/Kernel/KString.h +++ b/Kernel/KString.h @@ -91,6 +91,7 @@ struct Traits> : public GenericTraits const& p) { return string_hash(p->characters(), p->length()); } static bool equals(NonnullOwnPtr const& a, NonnullOwnPtr const& b) { return a->view() == b->view(); } + static bool equals(StringView a, NonnullOwnPtr const& b) { return a == b->view(); } }; template<> @@ -112,6 +113,19 @@ struct Traits> : public GenericTraitsview() == b->view(); } + static bool equals(StringView a, OwnPtr const& b) + { + if (!b) + return a.is_null(); + return a == b->view(); + } }; +namespace Detail { +template<> +inline constexpr bool IsHashCompatible> = true; +template<> +inline constexpr bool IsHashCompatible> = true; +} + }