mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
Kernel: Specialize Traits<(Nonnull)OwnPtr<T>> for KString
To make it behave like a string, since KString is always stored as a (Nonnull)OwnPtr in the kernel.
This commit is contained in:
parent
a21a3c2620
commit
d600f0d5b3
Notes:
sideshowbarker
2024-07-18 04:03:46 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/d600f0d5b3c Pull-request: https://github.com/SerenityOS/serenity/pull/9976
@ -63,4 +63,33 @@ struct Formatter<OwnPtr<Kernel::KString>> : Formatter<StringView> {
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Traits<NonnullOwnPtr<Kernel::KString>> : public GenericTraits<NonnullOwnPtr<Kernel::KString>> {
|
||||
using PeekType = Kernel::KString*;
|
||||
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(); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Traits<OwnPtr<Kernel::KString>> : public GenericTraits<OwnPtr<Kernel::KString>> {
|
||||
using PeekType = Kernel::KString*;
|
||||
using ConstPeekType = Kernel::KString const*;
|
||||
static unsigned hash(OwnPtr<Kernel::KString> const& p)
|
||||
{
|
||||
if (!p)
|
||||
return ptr_hash(nullptr);
|
||||
return string_hash(p->characters(), p->length());
|
||||
}
|
||||
static bool equals(OwnPtr<Kernel::KString> const& a, OwnPtr<Kernel::KString> const& b)
|
||||
{
|
||||
if (!a || !b)
|
||||
return a.ptr() == b.ptr();
|
||||
if (a == b)
|
||||
return true;
|
||||
|
||||
return a->view() == b->view();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user