mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
Kernel: Make {Nonnull,}OwnPtr<KString> hash compatible with StringView
This will allow us to use KString as HashTable/HashMap keys more easily
This commit is contained in:
parent
9b0d90a71d
commit
c68609b27f
Notes:
sideshowbarker
2024-07-17 20:01:06 +09:00
Author: https://github.com/IdanHo
Commit: c68609b27f
Pull-request: https://github.com/SerenityOS/serenity/pull/12205
Reviewed-by: https://github.com/bgianfo ✅
1 changed files with 14 additions and 0 deletions
|
@ -91,6 +91,7 @@ struct Traits<NonnullOwnPtr<Kernel::KString>> : public GenericTraits<NonnullOwnP
|
|||
using ConstPeekType = Kernel::KString const*;
|
||||
static unsigned hash(NonnullOwnPtr<Kernel::KString> const& p) { return string_hash(p->characters(), p->length()); }
|
||||
static bool equals(NonnullOwnPtr<Kernel::KString> const& a, NonnullOwnPtr<Kernel::KString> const& b) { return a->view() == b->view(); }
|
||||
static bool equals(StringView a, NonnullOwnPtr<Kernel::KString> const& b) { return a == b->view(); }
|
||||
};
|
||||
|
||||
template<>
|
||||
|
@ -112,6 +113,19 @@ struct Traits<OwnPtr<Kernel::KString>> : public GenericTraits<OwnPtr<Kernel::KSt
|
|||
|
||||
return a->view() == b->view();
|
||||
}
|
||||
static bool equals(StringView a, OwnPtr<Kernel::KString> const& b)
|
||||
{
|
||||
if (!b)
|
||||
return a.is_null();
|
||||
return a == b->view();
|
||||
}
|
||||
};
|
||||
|
||||
namespace Detail {
|
||||
template<>
|
||||
inline constexpr bool IsHashCompatible<StringView, NonnullOwnPtr<Kernel::KString>> = true;
|
||||
template<>
|
||||
inline constexpr bool IsHashCompatible<StringView, OwnPtr<Kernel::KString>> = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue