mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +00:00
LibCore: Use is<T> in Object::find_*_of_type helpers
This allows us to add fast-paths for commonly used types.
This commit is contained in:
parent
47dba83d30
commit
d6c6880674
1 changed files with 6 additions and 6 deletions
|
@ -190,8 +190,8 @@ template<typename T, typename Callback>
|
||||||
inline void Object::for_each_child_of_type(Callback callback) requires IsBaseOf<Object, T>
|
inline void Object::for_each_child_of_type(Callback callback) requires IsBaseOf<Object, T>
|
||||||
{
|
{
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
if (auto* child_as_t = dynamic_cast<T*>(&child); child_as_t)
|
if (is<T>(child))
|
||||||
return callback(*child_as_t);
|
return callback(static_cast<T&>(child));
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -212,11 +212,11 @@ T* Object::find_child_of_type_named(const String& name) requires IsBaseOf<Object
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* Object::find_descendant_of_type_named(const String& name) requires IsBaseOf<Object, T>
|
T* Object::find_descendant_of_type_named(String const& name) requires IsBaseOf<Object, T>
|
||||||
{
|
{
|
||||||
auto* this_as_t = dynamic_cast<T*>(this);
|
if (is<T>(*this) && this->name() == name) {
|
||||||
if (this_as_t && this->name() == name)
|
return static_cast<T*>(this);
|
||||||
return this_as_t;
|
}
|
||||||
T* found_child = nullptr;
|
T* found_child = nullptr;
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
found_child = child.template find_descendant_of_type_named<T>(name);
|
found_child = child.template find_descendant_of_type_named<T>(name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue