* drop any from meta containers rebind
* further reduce the size of the meta any vtable for containers
This commit is contained in:
Michele Caini
2023-08-04 09:33:22 +02:00
parent efbf5e3111
commit 1f99b49617
2 changed files with 10 additions and 12 deletions

2
TODO
View File

@@ -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:

View File

@@ -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)));
}
}