From 8b7f5e5668d7ef048e180f4849cd591ae6195367 Mon Sep 17 00:00:00 2001 From: skypjack Date: Sun, 14 Jul 2024 14:55:29 +0200 Subject: [PATCH] meta: reduce cost of constructing meta factories --- src/entt/meta/factory.hpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 95ab4d5cf..63a3fbdab 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -29,11 +29,6 @@ class basic_meta_factory { using bucket_type = dense_map; protected: - basic_meta_factory(const type_info &type, meta_ctx &area) - : info{&type}, - properties{}, - ctx{&area} {} - [[nodiscard]] inline decltype(auto) owner() { auto &&context = internal::meta_context::from(*ctx); ENTT_ASSERT(context.value.contains(info->hash()), "Type not available"); @@ -82,6 +77,20 @@ protected: (*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(); + } + + properties = &parent.details->prop; + } + private: const type_info *info; bucket_type *properties; @@ -125,15 +134,7 @@ public: * @param area The context into which to construct meta types. */ meta_factory(meta_ctx &area) noexcept - : internal::basic_meta_factory{type_id(), area} { - auto &&elem = this->owner(); - - if(!elem.details) { - elem.details = std::make_shared(); - } - - this->bucket(&elem.details->prop); - } + : internal::basic_meta_factory{type_id(), area} {} /** * @brief Assigns a custom unique identifier to a meta type.