LibCore: Use StringView in Object::find_{child,descendant}_of_type_named
It's unnecessary to allocate a string when we only want to compare it with another string. This change also adds a helper for string literals, so that we won't need to add -sv suffix everywhere. :^)
This commit is contained in:
parent
631fe129e9
commit
acf8e19eac
Notes:
sideshowbarker
2024-07-17 17:40:13 +09:00
Author: https://github.com/krkk Commit: https://github.com/SerenityOS/serenity/commit/acf8e19eac Pull-request: https://github.com/SerenityOS/serenity/pull/18840
1 changed files with 18 additions and 4 deletions
|
@ -128,13 +128,27 @@ public:
|
|||
requires IsBaseOf<Object, T>;
|
||||
|
||||
template<typename T>
|
||||
T* find_child_of_type_named(DeprecatedString const&)
|
||||
T* find_child_of_type_named(StringView)
|
||||
requires IsBaseOf<Object, T>;
|
||||
|
||||
template<typename T, size_t N>
|
||||
ALWAYS_INLINE T* find_child_of_type_named(char const (&string_literal)[N])
|
||||
requires IsBaseOf<Object, T>
|
||||
{
|
||||
return find_child_of_type_named<T>(StringView { string_literal, N - 1 });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* find_descendant_of_type_named(DeprecatedString const&)
|
||||
T* find_descendant_of_type_named(StringView)
|
||||
requires IsBaseOf<Object, T>;
|
||||
|
||||
template<typename T, size_t N>
|
||||
ALWAYS_INLINE T* find_descendant_of_type_named(char const (&string_literal)[N])
|
||||
requires IsBaseOf<Object, T>
|
||||
{
|
||||
return find_descendant_of_type_named<T>(StringView { string_literal, N - 1 });
|
||||
}
|
||||
|
||||
bool is_ancestor_of(Object const&) const;
|
||||
|
||||
Object* parent() { return m_parent; }
|
||||
|
@ -243,7 +257,7 @@ requires IsBaseOf<Object, T>
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
T* Object::find_child_of_type_named(DeprecatedString const& name)
|
||||
T* Object::find_child_of_type_named(StringView name)
|
||||
requires IsBaseOf<Object, T>
|
||||
{
|
||||
T* found_child = nullptr;
|
||||
|
@ -259,7 +273,7 @@ requires IsBaseOf<Object, T>
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
T* Object::find_descendant_of_type_named(DeprecatedString const& name)
|
||||
T* Object::find_descendant_of_type_named(StringView name)
|
||||
requires IsBaseOf<Object, T>
|
||||
{
|
||||
if (is<T>(*this) && this->name() == name) {
|
||||
|
|
Loading…
Add table
Reference in a new issue