From d600f0d5b3c601026054189a6a65b681be50fa47 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sun, 12 Sep 2021 00:15:47 +0430 Subject: [PATCH] Kernel: Specialize Traits<(Nonnull)OwnPtr> for KString To make it behave like a string, since KString is always stored as a (Nonnull)OwnPtr in the kernel. --- Kernel/KString.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Kernel/KString.h b/Kernel/KString.h index 0a06e5478b5..1a2af2f318d 100644 --- a/Kernel/KString.h +++ b/Kernel/KString.h @@ -63,4 +63,33 @@ struct Formatter> : Formatter { } }; +template<> +struct Traits> : public GenericTraits> { + using PeekType = Kernel::KString*; + using ConstPeekType = Kernel::KString const*; + static unsigned hash(NonnullOwnPtr const& p) { return string_hash(p->characters(), p->length()); } + static bool equals(NonnullOwnPtr const& a, NonnullOwnPtr const& b) { return a->view() == b->view(); } +}; + +template<> +struct Traits> : public GenericTraits> { + using PeekType = Kernel::KString*; + using ConstPeekType = Kernel::KString const*; + static unsigned hash(OwnPtr const& p) + { + if (!p) + return ptr_hash(nullptr); + return string_hash(p->characters(), p->length()); + } + static bool equals(OwnPtr const& a, OwnPtr const& b) + { + if (!a || !b) + return a.ptr() == b.ptr(); + if (a == b) + return true; + + return a->view() == b->view(); + } +}; + }