From 942df264021c1dd501441b61582a59bbfd3f8550 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 27 Aug 2024 11:58:13 +0200 Subject: [PATCH] meta: reduce cost of meta data --- src/entt/meta/factory.hpp | 32 +++++++++++++++++--------------- src/entt/meta/meta.hpp | 2 +- src/entt/meta/node.hpp | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 51708f678..dafafb4fb 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -31,13 +31,15 @@ class basic_meta_factory { using invoke_type = std::remove_pointer_t; template - auto *find_member(Type &from) { - return &from[bucket]; + static auto *find_member(Type &from, const id_type id) { + std::size_t pos{}; + for(const std::size_t last = from.size(); (pos != last) && (from[pos].id != id); ++pos) {} + return (pos == from.size()) ? nullptr : &from[pos]; } - auto *find_overload() { - auto *curr = find_member(details->func); - for(; curr->invoke != invoke; curr = curr->next.get()) {} + static auto *find_overload(meta_func_node *curr, invoke_type *const ref) { + for(; curr->invoke != ref; curr = curr->next.get()) {} + ENTT_ASSERT(curr != nullptr, "Cannot find overload"); return curr; } @@ -80,10 +82,10 @@ class basic_meta_factory { void data(meta_data_node node) { reset_bucket(node.id); - if(auto it = details->data.find(node.id); it == details->data.end()) { - details->data.insert_or_assign(node.id, std::move(node)); - } else if(it->second.set != node.set || it->second.get != node.get) { - it->second = std::move(node); + if(auto *member = find_member(details->data, node.id); member == nullptr) { + details->data.emplace_back(std::move(node)); + } else if(member->set != node.set || member->get != node.get) { + *member = std::move(node); } } @@ -116,9 +118,9 @@ class basic_meta_factory { if(bucket == parent) { container = &details->prop; } else if(invoke == nullptr) { - container = &find_member(details->data)->prop; + container = &find_member(details->data, bucket)->prop; } else { - container = &find_overload()->prop; + container = &find_overload(&details->func[bucket], invoke)->prop; // wait until func is a vector too: find_member(details->func, bucket); } std::size_t pos{}; @@ -130,9 +132,9 @@ class basic_meta_factory { if(bucket == parent) { meta_context::from(*ctx).value[bucket].traits |= value; } else if(invoke == nullptr) { - find_member(details->data)->traits |= value; + find_member(details->data, bucket)->traits |= value; } else { - find_overload()->traits |= value; + find_overload(&details->func[bucket], invoke)->traits |= value; // wait until func is a vector too: find_member(details->func, bucket); } } @@ -140,9 +142,9 @@ class basic_meta_factory { if(bucket == parent) { meta_context::from(*ctx).value[bucket].custom = std::move(node); } else if(invoke == nullptr) { - find_member(details->data)->custom = std::move(node); + find_member(details->data, bucket)->custom = std::move(node); } else { - find_overload()->custom = std::move(node); + find_overload(&details->func[bucket], invoke)->custom = std::move(node); // wait until func is a vector too: find_member(details->func, bucket); } } diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index dfba05f6b..9ec77131a 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -1432,7 +1432,7 @@ class meta_type { * @return The registered meta data for the given identifier, if any. */ [[nodiscard]] meta_data data(const id_type id) const { - const auto *elem = internal::deprecated_look_for<&internal::meta_type_descriptor::data>(internal::meta_context::from(*ctx), node, id); + const auto *elem = internal::look_for<&internal::meta_type_descriptor::data>(internal::meta_context::from(*ctx), node, id); return elem ? meta_data{*ctx, *elem} : meta_data{}; } diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index b16ad6d63..883863bb0 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -138,7 +138,7 @@ struct meta_type_descriptor { std::vector ctor{}; dense_map base{}; std::vector conv{}; - dense_map data{}; + std::vector data{}; dense_map func{}; std::vector prop{}; };