From d6c688067452ea0d0923edbb80e543b4dd5556f7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Apr 2021 23:01:24 +0200 Subject: LibCore: Use is in Object::find_*_of_type helpers This allows us to add fast-paths for commonly used types. --- Userland/Libraries/LibCore/Object.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Userland') 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 inline void Object::for_each_child_of_type(Callback callback) requires IsBaseOf { for_each_child([&](auto& child) { - if (auto* child_as_t = dynamic_cast(&child); child_as_t) - return callback(*child_as_t); + if (is(child)) + return callback(static_cast(child)); return IterationDecision::Continue; }); } @@ -212,11 +212,11 @@ T* Object::find_child_of_type_named(const String& name) requires IsBaseOf -T* Object::find_descendant_of_type_named(const String& name) requires IsBaseOf +T* Object::find_descendant_of_type_named(String const& name) requires IsBaseOf { - auto* this_as_t = dynamic_cast(this); - if (this_as_t && this->name() == name) - return this_as_t; + if (is(*this) && this->name() == name) { + return static_cast(this); + } T* found_child = nullptr; for_each_child([&](auto& child) { found_child = child.template find_descendant_of_type_named(name); -- cgit v1.2.3