meta: avoid creating a new shared_ptr if not needed (perf)

This commit is contained in:
skypjack
2025-08-28 12:39:16 +02:00
parent 47ff98e25b
commit 4760a09d61
2 changed files with 3 additions and 3 deletions

2
TODO
View File

@@ -35,6 +35,6 @@ TODO:
* meta non-const allow_cast overloads: (const int &) to (int &) is not allowed, but (const int &) to (double &) is allowed (support only for convertibles)
* review build process for testbed (i.e. tests first due to SDL)
* use any for meta_custom_node
* avoid copying meta_type/data/func nodes
* avoid copying meta_type/data/func nodes, and use unique_ptr for meta_custom
* paged vector as a standalone class
* resource: shared_from_this?

View File

@@ -786,7 +786,7 @@ struct meta_custom {
*/
template<typename Type>
[[nodiscard]] operator Type *() const noexcept {
return (type_id<Type>().hash() == node.type) ? std::static_pointer_cast<Type>(node.value).get() : nullptr;
return (type_id<Type>().hash() == node.type) ? static_cast<Type *>(node.value.get()) : nullptr;
}
/**
@@ -796,7 +796,7 @@ struct meta_custom {
template<typename Type>
[[nodiscard]] operator Type &() const noexcept {
ENTT_ASSERT(type_id<Type>().hash() == node.type, "Invalid type");
return *std::static_pointer_cast<Type>(node.value);
return *static_cast<Type *>(node.value.get());
}
private: