Browse Source

meta: remove the resolve function from meta_any to reduce the footprint

skypjack 4 months ago
parent
commit
19c0e8029d
1 changed files with 13 additions and 18 deletions
  1. 13 18
      src/entt/meta/meta.hpp

+ 13 - 18
src/entt/meta/meta.hpp

@@ -163,6 +163,11 @@ class meta_any {
     static void basic_vtable([[maybe_unused]] const internal::meta_traits req, [[maybe_unused]] const meta_ctx &area, [[maybe_unused]] const void *value, [[maybe_unused]] void *other) {
     static void basic_vtable([[maybe_unused]] const internal::meta_traits req, [[maybe_unused]] const meta_ctx &area, [[maybe_unused]] const void *value, [[maybe_unused]] void *other) {
         static_assert(std::is_same_v<std::remove_const_t<std::remove_reference_t<Type>>, Type>, "Invalid type");
         static_assert(std::is_same_v<std::remove_const_t<std::remove_reference_t<Type>>, Type>, "Invalid type");
 
 
+        if(req == internal::meta_traits::is_none) {
+            const auto &self = *static_cast<const meta_any *>(value);
+            self.node = &internal::resolve<Type>(internal::meta_context::from(area));
+        }
+
         if constexpr(is_meta_pointer_like_v<Type>) {
         if constexpr(is_meta_pointer_like_v<Type>) {
             if(req == internal::meta_traits::is_pointer_like) {
             if(req == internal::meta_traits::is_pointer_like) {
                 if constexpr(std::is_function_v<typename std::pointer_traits<Type>::element_type>) {
                 if constexpr(std::is_function_v<typename std::pointer_traits<Type>::element_type>) {
@@ -200,15 +205,18 @@ class meta_any {
         : storage{std::move(ref)},
         : storage{std::move(ref)},
           ctx{other.ctx} {
           ctx{other.ctx} {
         if(storage || !other.storage) {
         if(storage || !other.storage) {
-            resolve = other.resolve;
             node = other.node;
             node = other.node;
             vtable = other.vtable;
             vtable = other.vtable;
         }
         }
     }
     }
 
 
     [[nodiscard]] const auto &fetch_node() const {
     [[nodiscard]] const auto &fetch_node() const {
-        ENTT_ASSERT(resolve != nullptr, "Invalid resolve function");
-        return (node == nullptr) ? *(node = &resolve(internal::meta_context::from(*ctx))) : *node;
+        if(node == nullptr) {
+            ENTT_ASSERT(vtable != nullptr, "Invalid vtable function");
+            vtable(internal::meta_traits::is_none, *ctx, this, nullptr);
+        }
+
+        return *node;
     }
     }
 
 
 public:
 public:
@@ -243,7 +251,6 @@ public:
     explicit meta_any(const meta_ctx &area, std::in_place_type_t<Type>, Args &&...args)
     explicit meta_any(const meta_ctx &area, std::in_place_type_t<Type>, Args &&...args)
         : storage{std::in_place_type<Type>, std::forward<Args>(args)...},
         : storage{std::in_place_type<Type>, std::forward<Args>(args)...},
           ctx{&area},
           ctx{&area},
-          resolve{&internal::resolve<std::remove_const_t<std::remove_reference_t<Type>>>},
           vtable{&basic_vtable<std::remove_const_t<std::remove_reference_t<Type>>>} {}
           vtable{&basic_vtable<std::remove_const_t<std::remove_reference_t<Type>>>} {}
 
 
     /**
     /**
@@ -266,7 +273,6 @@ public:
         : storage{std::in_place, value},
         : storage{std::in_place, value},
           ctx{&area} {
           ctx{&area} {
         if(storage) {
         if(storage) {
-            resolve = &internal::resolve<Type>;
             vtable = &basic_vtable<Type>;
             vtable = &basic_vtable<Type>;
         }
         }
     }
     }
@@ -298,7 +304,6 @@ public:
     meta_any(const meta_ctx &area, const meta_any &other)
     meta_any(const meta_ctx &area, const meta_any &other)
         : storage{other.storage},
         : storage{other.storage},
           ctx{&area},
           ctx{&area},
-          resolve{other.resolve},
           node{(ctx == other.ctx) ? other.node : nullptr},
           node{(ctx == other.ctx) ? other.node : nullptr},
           vtable{other.vtable} {}
           vtable{other.vtable} {}
 
 
@@ -310,7 +315,6 @@ public:
     meta_any(const meta_ctx &area, meta_any &&other)
     meta_any(const meta_ctx &area, meta_any &&other)
         : storage{std::move(other.storage)},
         : storage{std::move(other.storage)},
           ctx{&area},
           ctx{&area},
-          resolve{std::exchange(other.resolve, nullptr)},
           node{(ctx == other.ctx) ? std::exchange(other.node, nullptr) : nullptr},
           node{(ctx == other.ctx) ? std::exchange(other.node, nullptr) : nullptr},
           vtable{std::exchange(other.vtable, nullptr)} {}
           vtable{std::exchange(other.vtable, nullptr)} {}
 
 
@@ -327,7 +331,6 @@ public:
     meta_any(meta_any &&other) noexcept
     meta_any(meta_any &&other) noexcept
         : storage{std::move(other.storage)},
         : storage{std::move(other.storage)},
           ctx{other.ctx},
           ctx{other.ctx},
-          resolve{std::exchange(other.resolve, nullptr)},
           node{std::exchange(other.node, nullptr)},
           node{std::exchange(other.node, nullptr)},
           vtable{std::exchange(other.vtable, nullptr)} {}
           vtable{std::exchange(other.vtable, nullptr)} {}
 
 
@@ -343,7 +346,6 @@ public:
         if(this != &other) {
         if(this != &other) {
             storage = other.storage;
             storage = other.storage;
             ctx = other.ctx;
             ctx = other.ctx;
-            resolve = other.resolve;
             node = other.node;
             node = other.node;
             vtable = other.vtable;
             vtable = other.vtable;
         }
         }
@@ -359,7 +361,6 @@ public:
     meta_any &operator=(meta_any &&other) noexcept {
     meta_any &operator=(meta_any &&other) noexcept {
         storage = std::move(other.storage);
         storage = std::move(other.storage);
         ctx = other.ctx;
         ctx = other.ctx;
-        resolve = std::exchange(other.resolve, nullptr);
         node = std::exchange(other.node, nullptr);
         node = std::exchange(other.node, nullptr);
         vtable = std::exchange(other.vtable, nullptr);
         vtable = std::exchange(other.vtable, nullptr);
         return *this;
         return *this;
@@ -506,12 +507,8 @@ public:
     template<typename Type, typename... Args>
     template<typename Type, typename... Args>
     void emplace(Args &&...args) {
     void emplace(Args &&...args) {
         storage.emplace<Type>(std::forward<Args>(args)...);
         storage.emplace<Type>(std::forward<Args>(args)...);
-
-        if(auto *overload = &internal::resolve<std::remove_const_t<std::remove_reference_t<Type>>>; overload != resolve) {
-            resolve = overload;
-            node = nullptr;
-            vtable = &basic_vtable<std::remove_const_t<std::remove_reference_t<Type>>>;
-        }
+        node = nullptr;
+        vtable = &basic_vtable<std::remove_const_t<std::remove_reference_t<Type>>>;
     }
     }
 
 
     /*! @copydoc any::assign */
     /*! @copydoc any::assign */
@@ -523,7 +520,6 @@ public:
     /*! @copydoc any::reset */
     /*! @copydoc any::reset */
     void reset() {
     void reset() {
         storage.reset();
         storage.reset();
-        resolve = nullptr;
         node = nullptr;
         node = nullptr;
         vtable = nullptr;
         vtable = nullptr;
     }
     }
@@ -620,7 +616,6 @@ public:
 private:
 private:
     any storage{};
     any storage{};
     const meta_ctx *ctx{&locator<meta_ctx>::value_or()};
     const meta_ctx *ctx{&locator<meta_ctx>::value_or()};
-    const internal::meta_type_node &(*resolve)(const internal::meta_context &) noexcept {};
     mutable const internal::meta_type_node *node{};
     mutable const internal::meta_type_node *node{};
     vtable_type *vtable{};
     vtable_type *vtable{};
 };
 };