From eee348f6b14df86772aceb6d26deaba082ed6dae Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 27 Aug 2024 12:28:58 +0200 Subject: [PATCH] meta: reduce cost of meta base --- src/entt/meta/factory.hpp | 7 ++++--- src/entt/meta/meta.hpp | 4 +++- src/entt/meta/node.hpp | 9 ++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 31dd469f0..11c40da7a 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -62,15 +62,16 @@ class basic_meta_factory { void insert_or_assign(Type node) { reset_bucket(parent); + std::size_t pos{}; + if constexpr(std::is_same_v) { - details->base.insert_or_assign(node.id, node); + for(const std::size_t last = details->base.size(); (pos != last) && (details->base[pos].id != node.id); ++pos) {} + (pos == details->base.size()) ? details->base.emplace_back(node) : (details->base[pos] = node); } else if constexpr(std::is_same_v) { - std::size_t pos{}; for(const std::size_t last = details->conv.size(); (pos != last) && (details->conv[pos].type != node.type); ++pos) {} (pos == details->conv.size()) ? details->conv.emplace_back(node) : (details->conv[pos] = node); } else { static_assert(std::is_same_v, "Unexpected type"); - std::size_t pos{}; for(const std::size_t last = details->ctor.size(); (pos != last) && (details->ctor[pos].id != node.id); ++pos) {} (pos == details->ctor.size()) ? details->ctor.emplace_back(node) : (details->ctor[pos] = node); } diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 6f1ffbdb0..52821de40 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -1179,7 +1179,9 @@ class meta_type { bool can_continue = type.node.conversion_helper && other.node.conversion_helper; if(!can_continue && type.node.details) { - can_continue = type.node.details->base.contains(info.hash()); + for(std::size_t idx{}, last = type.node.details->base.size(); !can_continue && idx != last; ++idx) { + can_continue = (type.node.details->base[idx].id == info.hash()); + } for(std::size_t idx{}, last = type.node.details->conv.size(); !can_continue && idx != last; ++idx) { can_continue = (type.node.details->conv[idx].type == info.hash()); diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index 1da2fede8..b5ac83d37 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -7,7 +7,6 @@ #include #include #include "../config/config.h" -#include "../container/dense_map.hpp" #include "../core/attribute.h" #include "../core/bit.hpp" #include "../core/enum.hpp" @@ -136,7 +135,7 @@ struct meta_template_node { struct meta_type_descriptor { std::vector ctor{}; - dense_map base{}; + std::vector base{}; std::vector conv{}; std::vector data{}; std::vector func{}; @@ -171,7 +170,7 @@ auto *look_for(const meta_context &context, const meta_type_node &node, const id } for(auto &&curr: node.details->base) { - if(auto *elem = look_for(context, curr.second.type(context), id); elem) { + if(auto *elem = look_for(context, curr.type(context), id); elem) { return elem; } } @@ -199,7 +198,7 @@ template if(from.details) { for(auto &&curr: from.details->base) { - if(const void *elem = try_cast(context, curr.second.type(context), to, curr.second.cast(instance)); elem) { + if(const void *elem = try_cast(context, curr.type(context), to, curr.cast(instance)); elem) { return elem; } } @@ -222,7 +221,7 @@ template } for(auto &&curr: from.details->base) { - if(auto other = try_convert(context, curr.second.type(context), to, arithmetic_or_enum, curr.second.cast(instance), func); other) { + if(auto other = try_convert(context, curr.type(context), to, arithmetic_or_enum, curr.cast(instance), func); other) { return other; } }