From 5ef4a2f22acd0f839791f33922997e183bfe58c2 Mon Sep 17 00:00:00 2001 From: Paolo Monteverde Date: Fri, 13 Dec 2024 14:35:05 +0100 Subject: [PATCH] meta: avoid pointless lookups in try_cast (#1201) --- src/entt/meta/meta.hpp | 6 +++--- src/entt/meta/node.hpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 73f3ec7cd..a25c6e8ad 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -438,7 +438,7 @@ public: */ template [[nodiscard]] const Type *try_cast() const { - const auto other = internal::resolve>(internal::meta_context::from(*ctx)); + const auto &other = type_id>(); return static_cast(internal::try_cast(internal::meta_context::from(*ctx), node, other, storage.data())); } @@ -448,7 +448,7 @@ public: if constexpr(std::is_const_v) { return std::as_const(*this).try_cast>(); } else { - const auto other = internal::resolve>(internal::meta_context::from(*ctx)); + const auto &other = type_id>(); return static_cast(const_cast(internal::try_cast(internal::meta_context::from(*ctx), node, other, storage.data()))); } } @@ -1304,7 +1304,7 @@ public: */ [[nodiscard]] bool can_cast(const meta_type &other) const noexcept { // casting this is UB in all cases but we aren't going to use the resulting pointer, so... - return (internal::try_cast(internal::meta_context::from(*ctx), node, other.node, this) != nullptr); + return (other.node.info != nullptr) && (internal::try_cast(internal::meta_context::from(*ctx), node, *other.node.info, this) != nullptr); } /** diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index a0756c238..1719d15f1 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -198,8 +198,8 @@ template return value(context); } -[[nodiscard]] inline const void *try_cast(const meta_context &context, const meta_type_node &from, const meta_type_node &to, const void *instance) noexcept { - if((from.info != nullptr) && (to.info != nullptr) && *from.info == *to.info) { +[[nodiscard]] inline const void *try_cast(const meta_context &context, const meta_type_node &from, const type_info &to, const void *instance) noexcept { + if((from.info != nullptr) && *from.info == to) { return instance; }