mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 09:27:35 +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
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*;
|
using ConstPeekType = Kernel::KString const*;
|
||||||
static unsigned hash(NonnullOwnPtr<Kernel::KString> const& p) { return string_hash(p->characters(), p->length()); }
|
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(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<>
|
template<>
|
||||||
|
@ -112,6 +113,19 @@ struct Traits<OwnPtr<Kernel::KString>> : public GenericTraits<OwnPtr<Kernel::KSt
|
||||||
|
|
||||||
return a->view() == b->view();
|
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