Skip to content

Commit

Permalink
meta: reduce cost of meta ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Aug 27, 2024
1 parent 94735d0 commit 5da2c3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/entt/meta/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class basic_meta_factory {
details->conv.insert_or_assign(node.type, node);
} else {
static_assert(std::is_same_v<Type, meta_ctor_node>, "Unexpected type");
details->ctor.insert_or_assign(node.id, node);
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
2 changes: 1 addition & 1 deletion src/entt/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ class meta_type {
*/
[[nodiscard]] meta_any construct(meta_any *const args, const size_type sz) const {
if(node.details) {
if(const auto *candidate = lookup(args, sz, false, [first = node.details->ctor.cbegin(), last = node.details->ctor.cend()]() mutable { return first == last ? nullptr : &(first++)->second; }); candidate) {
if(const auto *candidate = lookup(args, sz, false, [first = node.details->ctor.cbegin(), last = node.details->ctor.cend()]() mutable { return first == last ? nullptr : &*(first++); }); candidate) {
return candidate->invoke(*ctx, args);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/entt/meta/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include "../config/config.h"
#include "../container/dense_map.hpp"
#include "../core/attribute.h"
Expand Down Expand Up @@ -134,7 +135,7 @@ struct meta_template_node {
};

struct meta_type_descriptor {
dense_map<id_type, meta_ctor_node, identity> ctor{};
std::vector<meta_ctor_node> ctor{};
dense_map<id_type, meta_base_node, identity> base{};
dense_map<id_type, meta_conv_node, identity> conv{};
dense_map<id_type, meta_data_node, identity> data{};
Expand Down

0 comments on commit 5da2c3c

Please sign in to comment.