Browse Source

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

skypjack 6 months ago
parent
commit
4760a09d61
2 changed files with 3 additions and 3 deletions
  1. 1 1
      TODO
  2. 2 2
      src/entt/meta/meta.hpp

+ 1 - 1
TODO

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

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

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