diff options
author | Andreas Kling <kling@serenityos.org> | 2021-04-17 23:01:24 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-17 23:01:24 +0200 |
commit | d6c688067452ea0d0923edbb80e543b4dd5556f7 (patch) | |
tree | c1c9b20e2066aecbfe90e5043585f730fa1421a5 /Userland/Libraries/LibCore/Object.h | |
parent | 47dba83d301a176f79eb87ef4393f02d578e2255 (diff) | |
download | serenity-d6c688067452ea0d0923edbb80e543b4dd5556f7.zip |
LibCore: Use is<T> in Object::find_*_of_type helpers
This allows us to add fast-paths for commonly used types.
Diffstat (limited to 'Userland/Libraries/LibCore/Object.h')
-rw-r--r-- | Userland/Libraries/LibCore/Object.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibCore/Object.h b/Userland/Libraries/LibCore/Object.h index dd76f2592a..0aca8d7370 100644 --- a/Userland/Libraries/LibCore/Object.h +++ b/Userland/Libraries/LibCore/Object.h @@ -190,8 +190,8 @@ template<typename T, typename Callback> inline void Object::for_each_child_of_type(Callback callback) requires IsBaseOf<Object, T> { for_each_child([&](auto& child) { - if (auto* child_as_t = dynamic_cast<T*>(&child); child_as_t) - return callback(*child_as_t); + if (is<T>(child)) + return callback(static_cast<T&>(child)); return IterationDecision::Continue; }); } @@ -212,11 +212,11 @@ T* Object::find_child_of_type_named(const String& name) requires IsBaseOf<Object } 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 (this_as_t && this->name() == name) - return this_as_t; + if (is<T>(*this) && this->name() == name) { + return static_cast<T*>(this); + } T* found_child = nullptr; for_each_child([&](auto& child) { found_child = child.template find_descendant_of_type_named<T>(name); |