Explorar el Código

meta:
* drop any from meta containers rebind
* further reduce the size of the meta any vtable for containers

Michele Caini hace 2 años
padre
commit
1f99b49617
Se han modificado 2 ficheros con 10 adiciones y 12 borrados
  1. 1 1
      TODO
  2. 9 11
      src/entt/meta/meta.hpp

+ 1 - 1
TODO

@@ -17,7 +17,7 @@ TODO (high prio):
 * view with entity storage: begin/end should return filtered iterators
 * update view doc: single vs multi type views are no longer a thing actually
 * meta container: add value type to resize
-* meta: make meta container rebind type based (no any)
+* meta: further reduce container vtable (ie move checks on key cast to the callsite)
 * ===> TEST: review view tests after the last changes
 
 WIP:

+ 9 - 11
src/entt/meta/meta.hpp

@@ -54,11 +54,10 @@ public:
      * @param instance The container to wrap.
      */
     template<typename Type>
-    void rebind(any instance) noexcept {
-        ENTT_ASSERT(instance.type() == type_id<Type>(), "Unexpected type");
+    void rebind(Type &instance) noexcept {
         value_type_node = &internal::resolve<typename Type::value_type>;
-        vtable = &meta_sequence_container_traits<Type>::basic_vtable;
-        storage = std::move(instance);
+        vtable = &meta_sequence_container_traits<std::remove_const_t<Type>>::basic_vtable;
+        storage = forward_as_any(instance);
     }
 
     [[nodiscard]] inline meta_type value_type() const noexcept;
@@ -108,17 +107,16 @@ public:
      * @param instance The container to wrap.
      */
     template<typename Type>
-    void rebind(any instance) noexcept {
-        ENTT_ASSERT(instance.type() == type_id<Type>(), "Unexpected type");
+    void rebind(Type &instance) noexcept {
         key_type_node = &internal::resolve<typename Type::key_type>;
         value_type_node = &internal::resolve<typename Type::value_type>;
 
-        if constexpr(!meta_associative_container_traits<Type>::key_only) {
+        if constexpr(!meta_associative_container_traits<std::remove_const_t<Type>>::key_only) {
             mapped_type_node = &internal::resolve<typename Type::mapped_type>;
         }
 
-        vtable = meta_associative_container_traits<Type>::basic_vtable;
-        storage = std::move(instance);
+        vtable = meta_associative_container_traits<std::remove_const_t<Type>>::basic_vtable;
+        storage = forward_as_any(instance);
     }
 
     [[nodiscard]] inline meta_type key_type() const noexcept;
@@ -167,9 +165,9 @@ class meta_any {
                 }
             }
         } else if constexpr(is_complete_v<meta_sequence_container_traits<Type>>) {
-            const_only ? static_cast<meta_sequence_container *>(other)->rebind<Type>(forward_as_any(*static_cast<const Type *>(value))) : static_cast<meta_sequence_container *>(other)->rebind<Type>(forward_as_any(*static_cast<Type *>(const_cast<void *>(value))));
+            const_only ? static_cast<meta_sequence_container *>(other)->rebind(*static_cast<const Type *>(value)) : static_cast<meta_sequence_container *>(other)->rebind(*static_cast<Type *>(const_cast<void *>(value)));
         } else if constexpr(is_complete_v<meta_associative_container_traits<Type>>) {
-            const_only ? static_cast<meta_associative_container *>(other)->rebind<Type>(forward_as_any(*static_cast<const Type *>(value))) : static_cast<meta_associative_container *>(other)->rebind<Type>(forward_as_any(*static_cast<Type *>(const_cast<void *>(value))));
+            const_only ? static_cast<meta_associative_container *>(other)->rebind(*static_cast<const Type *>(value)) : static_cast<meta_associative_container *>(other)->rebind(*static_cast<Type *>(const_cast<void *>(value)));
         }
     }