Skip to content

Commit

Permalink
meta:
Browse files Browse the repository at this point in the history
* drop any from meta containers rebind
* further reduce the size of the meta any vtable for containers
  • Loading branch information
skypjack committed Aug 4, 2023
1 parent 3056839 commit ff9dd9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 9 additions & 11 deletions src/entt/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ class meta_sequence_container {
* @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;
Expand Down Expand Up @@ -108,17 +107,16 @@ class meta_associative_container {
* @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;
Expand Down Expand Up @@ -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)));
}
}

Expand Down

0 comments on commit ff9dd9e

Please sign in to comment.