Răsfoiți Sursa

meta: review conversion_helper for meta type nodes

Michele Caini 4 ani în urmă
părinte
comite
24a537d154
2 a modificat fișierele cu 7 adăugiri și 6 ștergeri
  1. 2 1
      src/entt/meta/meta.hpp
  2. 5 5
      src/entt/meta/node.hpp

+ 2 - 1
src/entt/meta/meta.hpp

@@ -1374,7 +1374,8 @@ bool meta_any::set(const id_type id, Type &&value) {
         // exploits the fact that arithmetic types and enums are also default constructible
         // exploits the fact that arithmetic types and enums are also default constructible
         auto other = type.construct();
         auto other = type.construct();
         ENTT_ASSERT(other.node->conversion_helper, "Conversion helper not found");
         ENTT_ASSERT(other.node->conversion_helper, "Conversion helper not found");
-        other.node->conversion_helper(other.storage, node->conversion_helper(storage, {}));
+        const auto value = node->conversion_helper(nullptr, storage.data());
+        other.node->conversion_helper(other.storage.data(), &value);
         return other;
         return other;
     }
     }
 
 

+ 5 - 5
src/entt/meta/node.hpp

@@ -109,7 +109,7 @@ struct meta_type_node {
     const size_type size_of;
     const size_type size_of;
     const meta_traits traits;
     const meta_traits traits;
     meta_any (*const default_constructor)();
     meta_any (*const default_constructor)();
-    double (*const conversion_helper)(const any &, const any &);
+    double (*const conversion_helper)(void *, const void *);
     const meta_template_node *const templ;
     const meta_template_node *const templ;
     meta_ctor_node *ctor{nullptr};
     meta_ctor_node *ctor{nullptr};
     meta_base_node *base{nullptr};
     meta_base_node *base{nullptr};
@@ -136,12 +136,12 @@ class ENTT_API meta_node {
 
 
     [[nodiscard]] static auto *meta_conversion_helper() ENTT_NOEXCEPT {
     [[nodiscard]] static auto *meta_conversion_helper() ENTT_NOEXCEPT {
         if constexpr(std::is_arithmetic_v<Type>) {
         if constexpr(std::is_arithmetic_v<Type>) {
-            return +[](const any &storage, const any &value) {
-                return value ? static_cast<double>(any_cast<Type &>(const_cast<any &>(storage)) = static_cast<Type>(any_cast<double>(value))) : static_cast<double>(any_cast<const Type &>(storage));
+            return +[](void *bin, const void *value) {
+                return bin ? static_cast<double>(*static_cast<Type *>(bin) = static_cast<Type>(*static_cast<const double *>(value))) : static_cast<double>(*static_cast<const Type *>(value));
             };
             };
         } else if constexpr(std::is_enum_v<Type>) {
         } else if constexpr(std::is_enum_v<Type>) {
-            return +[](const any &storage, const any &value) {
-                return value ? static_cast<double>(any_cast<Type &>(const_cast<any &>(storage)) = static_cast<Type>(static_cast<std::underlying_type_t<Type>>(any_cast<double>(value)))) : static_cast<double>(any_cast<const Type &>(storage));
+            return +[](void *bin, const void *value) {
+                return bin ? static_cast<double>(*static_cast<Type *>(bin) = static_cast<Type>(static_cast<std::underlying_type_t<Type>>(*static_cast<const double *>(value)))) : static_cast<double>(*static_cast<const Type *>(value));
             };
             };
         } else {
         } else {
             return static_cast<decltype(meta_type_node::conversion_helper)>(nullptr);
             return static_cast<decltype(meta_type_node::conversion_helper)>(nullptr);