From 626b882f266c3f7d7b36359fd5b239ef34f0da8b Mon Sep 17 00:00:00 2001 From: skypjack Date: Wed, 3 Sep 2025 17:00:22 +0200 Subject: [PATCH] meta: reduce uses of node in meta_any --- src/entt/meta/meta.hpp | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 282d011f1..a1b500e30 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -157,34 +157,40 @@ private: /*! @brief Opaque wrapper for values of any type. */ class meta_any { - using vtable_type = void(const meta_ctx &, void *, const void *, void *); + using vtable_type = void(const internal::meta_traits, const meta_ctx &, void *, const void *, void *); template - static void basic_vtable([[maybe_unused]] const meta_ctx &area, [[maybe_unused]] void *value, [[maybe_unused]] const void *as_const, [[maybe_unused]] void *other) { + static void basic_vtable([[mayb_unused]] const internal::meta_traits req, [[maybe_unused]] const meta_ctx &area, [[maybe_unused]] void *value, [[maybe_unused]] const void *as_const, [[maybe_unused]] void *other) { static_assert(std::is_same_v>, Type>, "Invalid type"); if constexpr(is_meta_pointer_like_v) { - if constexpr(std::is_function_v::element_type>) { - static_cast(other)->emplace(*static_cast(as_const)); - } else if constexpr(!std::is_void_v::element_type>>) { - using in_place_type = decltype(adl_meta_pointer_like::dereference(std::declval())); + if(req == internal::meta_traits::is_pointer_like) { + if constexpr(std::is_function_v::element_type>) { + static_cast(other)->emplace(*static_cast(as_const)); + } else if constexpr(!std::is_void_v::element_type>>) { + using in_place_type = decltype(adl_meta_pointer_like::dereference(std::declval())); - if constexpr(std::is_constructible_v) { - if(const auto &pointer_like = *static_cast(as_const); pointer_like) { - static_cast(other)->emplace(adl_meta_pointer_like::dereference(pointer_like)); + if constexpr(std::is_constructible_v) { + if(const auto &pointer_like = *static_cast(as_const); pointer_like) { + static_cast(other)->emplace(adl_meta_pointer_like::dereference(pointer_like)); + } + } else { + static_cast(other)->emplace(adl_meta_pointer_like::dereference(*static_cast(as_const))); } - } else { - static_cast(other)->emplace(adl_meta_pointer_like::dereference(*static_cast(as_const))); } } } if constexpr(is_complete_v>) { - *static_cast(other) = (value == nullptr) ? meta_sequence_container{area, *static_cast(as_const)} : meta_sequence_container{area, *static_cast(value)}; + if(req == internal::meta_traits::is_sequence_container) { + *static_cast(other) = (value == nullptr) ? meta_sequence_container{area, *static_cast(as_const)} : meta_sequence_container{area, *static_cast(value)}; + } } if constexpr(is_complete_v>) { - *static_cast(other) = (value == nullptr) ? meta_associative_container{area, *static_cast(as_const)} : meta_associative_container{area, *static_cast(value)}; + if(req == internal::meta_traits::is_associative_container) { + *static_cast(other) = (value == nullptr) ? meta_associative_container{area, *static_cast(as_const)} : meta_associative_container{area, *static_cast(value)}; + } } } @@ -546,14 +552,14 @@ public: */ [[nodiscard]] meta_sequence_container as_sequence_container() noexcept { meta_sequence_container proxy{}; - if(!!(node.traits & internal::meta_traits::is_sequence_container)) { vtable(*ctx, storage.data(), std::as_const(storage).data(), &proxy); } + if(vtable != nullptr) { vtable(internal::meta_traits::is_sequence_container, *ctx, storage.data(), std::as_const(storage).data(), &proxy); } return proxy; } /*! @copydoc as_sequence_container */ [[nodiscard]] meta_sequence_container as_sequence_container() const noexcept { meta_sequence_container proxy{}; - if(!!(node.traits & internal::meta_traits::is_sequence_container)) { vtable(*ctx, nullptr, storage.data(), &proxy); } + if(vtable != nullptr) { vtable(internal::meta_traits::is_sequence_container, *ctx, nullptr, storage.data(), &proxy); } return proxy; } @@ -563,14 +569,14 @@ public: */ [[nodiscard]] meta_associative_container as_associative_container() noexcept { meta_associative_container proxy{}; - if(!!(node.traits & internal::meta_traits::is_associative_container)) { vtable(*ctx, storage.data(), std::as_const(storage).data(), &proxy); } + if(vtable != nullptr) { vtable(internal::meta_traits::is_associative_container, *ctx, storage.data(), std::as_const(storage).data(), &proxy); } return proxy; } /*! @copydoc as_associative_container */ [[nodiscard]] meta_associative_container as_associative_container() const noexcept { meta_associative_container proxy{}; - if(!!(node.traits & internal::meta_traits::is_associative_container)) { vtable(*ctx, nullptr, storage.data(), &proxy); } + if(vtable != nullptr) { vtable(internal::meta_traits::is_associative_container, *ctx, nullptr, storage.data(), &proxy); } return proxy; } @@ -581,7 +587,7 @@ public: */ [[nodiscard]] meta_any operator*() const noexcept { meta_any ret{meta_ctx_arg, *ctx}; - if(!!(node.traits & internal::meta_traits::is_pointer_like)) { vtable(*ctx, nullptr, storage.data(), &ret); } + if(vtable != nullptr) { vtable(internal::meta_traits::is_pointer_like, *ctx, nullptr, storage.data(), &ret); } return ret; }