mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
AK+Kernel: Unify Traits<T>::equals()'s argument order on different types
There was a small mishmash of argument order, as seen on the table: | Traits<T>::equals(U, T) | Traits<T>::equals(T, U) ============= | ======================= | ======================= uses equals() | HashMap | Vector, HashTable defines equals() | *String[^1] | ByteBuffer [^1]: String, DeprecatedString, their Fly-type equivalents and KString. This mostly meant that you couldn't use a StringView for finding a value in Vector<String>. I'm changing the order of arguments to make the trait type itself first (`Traits<T>::equals(T, U)`), as I think it's more expected and makes us more consistent with the rest of the functions that put the stored type first (like StringUtils functions and binary_serach). I've also renamed the variable name "other" in find functions to "entry" to give more importance to the value. With this change, each of the following lines will now compile successfully: Vector<String>().contains_slow("WHF!"sv); HashTable<String>().contains("WHF!"sv); HashMap<ByteBuffer, int>().contains("WHF!"sv.bytes());
This commit is contained in:
parent
5ff7448fee
commit
e575ee4462
7 changed files with 26 additions and 16 deletions
|
@ -91,7 +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(); }
|
||||
static bool equals(NonnullOwnPtr<Kernel::KString> const& a, StringView b) { return a->view() == b; }
|
||||
};
|
||||
|
||||
template<>
|
||||
|
@ -113,11 +113,11 @@ 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)
|
||||
static bool equals(OwnPtr<Kernel::KString> const& a, StringView b)
|
||||
{
|
||||
if (!b)
|
||||
return a.is_null();
|
||||
return a == b->view();
|
||||
if (!a)
|
||||
return b.is_null();
|
||||
return a->view() == b;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue