Skip to content

Commit

Permalink
meta: reduce cost of meta base
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Aug 27, 2024
1 parent c7e8a99 commit eee348f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/entt/meta/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, meta_base_node>) {
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<Type, meta_conv_node>) {
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<Type, meta_ctor_node>, "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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/entt/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
9 changes: 4 additions & 5 deletions src/entt/meta/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <utility>
#include <vector>
#include "../config/config.h"
#include "../container/dense_map.hpp"
#include "../core/attribute.h"
#include "../core/bit.hpp"
#include "../core/enum.hpp"
Expand Down Expand Up @@ -136,7 +135,7 @@ struct meta_template_node {

struct meta_type_descriptor {
std::vector<meta_ctor_node> ctor{};
dense_map<id_type, meta_base_node, identity> base{};
std::vector<meta_base_node> base{};
std::vector<meta_conv_node> conv{};
std::vector<meta_data_node> data{};
std::vector<meta_func_node> func{};
Expand Down Expand Up @@ -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<Member>(context, curr.second.type(context), id); elem) {
if(auto *elem = look_for<Member>(context, curr.type(context), id); elem) {
return elem;
}
}
Expand Down Expand Up @@ -199,7 +198,7 @@ template<typename... Args>

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;
}
}
Expand All @@ -222,7 +221,7 @@ template<typename Func>
}

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;
}
}
Expand Down

0 comments on commit eee348f

Please sign in to comment.