mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
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
1 changed files with 18 additions and 4 deletions
|
@ -128,13 +128,27 @@ public:
|
||||||
requires IsBaseOf<Object, T>;
|
requires IsBaseOf<Object, T>;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* find_child_of_type_named(DeprecatedString const&)
|
T* find_child_of_type_named(StringView)
|
||||||
requires IsBaseOf<Object, T>;
|
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>
|
template<typename T>
|
||||||
T* find_descendant_of_type_named(DeprecatedString const&)
|
T* find_descendant_of_type_named(StringView)
|
||||||
requires IsBaseOf<Object, T>;
|
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;
|
bool is_ancestor_of(Object const&) const;
|
||||||
|
|
||||||
Object* parent() { return m_parent; }
|
Object* parent() { return m_parent; }
|
||||||
|
@ -243,7 +257,7 @@ requires IsBaseOf<Object, T>
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename 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>
|
requires IsBaseOf<Object, T>
|
||||||
{
|
{
|
||||||
T* found_child = nullptr;
|
T* found_child = nullptr;
|
||||||
|
@ -259,7 +273,7 @@ requires IsBaseOf<Object, T>
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename 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>
|
requires IsBaseOf<Object, T>
|
||||||
{
|
{
|
||||||
if (is<T>(*this) && this->name() == name) {
|
if (is<T>(*this) && this->name() == name) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue