Browse Source

meta: reduce cost of constructing meta factories

skypjack 1 year ago
parent
commit
8b7f5e5668
1 changed files with 15 additions and 14 deletions
  1. 15 14
      src/entt/meta/factory.hpp

+ 15 - 14
src/entt/meta/factory.hpp

@@ -29,11 +29,6 @@ class basic_meta_factory {
     using bucket_type = dense_map<id_type, internal::meta_prop_node, identity>;
     using bucket_type = dense_map<id_type, internal::meta_prop_node, identity>;
 
 
 protected:
 protected:
-    basic_meta_factory(const type_info &type, meta_ctx &area)
-        : info{&type},
-          properties{},
-          ctx{&area} {}
-
     [[nodiscard]] inline decltype(auto) owner() {
     [[nodiscard]] inline decltype(auto) owner() {
         auto &&context = internal::meta_context::from(*ctx);
         auto &&context = internal::meta_context::from(*ctx);
         ENTT_ASSERT(context.value.contains(info->hash()), "Type not available");
         ENTT_ASSERT(context.value.contains(info->hash()), "Type not available");
@@ -82,6 +77,20 @@ protected:
         (*properties)[key] = std::move(value);
         (*properties)[key] = std::move(value);
     }
     }
 
 
+public:
+    basic_meta_factory(const type_info &type, meta_ctx &area)
+        : info{&type},
+          properties{},
+          ctx{&area} {
+        auto &&parent = owner();
+
+        if(!parent.details) {
+            parent.details = std::make_shared<internal::meta_type_descriptor>();
+        }
+
+        properties = &parent.details->prop;
+    }
+
 private:
 private:
     const type_info *info;
     const type_info *info;
     bucket_type *properties;
     bucket_type *properties;
@@ -125,15 +134,7 @@ public:
      * @param area The context into which to construct meta types.
      * @param area The context into which to construct meta types.
      */
      */
     meta_factory(meta_ctx &area) noexcept
     meta_factory(meta_ctx &area) noexcept
-        : internal::basic_meta_factory{type_id<Type>(), area} {
-        auto &&elem = this->owner();
-
-        if(!elem.details) {
-            elem.details = std::make_shared<internal::meta_type_descriptor>();
-        }
-
-        this->bucket(&elem.details->prop);
-    }
+        : internal::basic_meta_factory{type_id<Type>(), area} {}
 
 
     /**
     /**
      * @brief Assigns a custom unique identifier to a meta type.
      * @brief Assigns a custom unique identifier to a meta type.