Ver Fonte

meta: prepare to more perf improvements

skypjack há 2 meses atrás
pai
commit
bfd7320609

+ 3 - 1
src/entt/meta/context.hpp

@@ -15,7 +15,9 @@ namespace internal {
 struct meta_type_node;
 
 struct meta_context {
-    dense_map<id_type, std::unique_ptr<meta_type_node>, stl::identity> value;
+    using container_type = dense_map<id_type, std::unique_ptr<meta_type_node>, stl::identity>;
+
+    container_type bucket;
 
     [[nodiscard]] inline static meta_context &from(meta_ctx &);
     [[nodiscard]] inline static const meta_context &from(const meta_ctx &);

+ 6 - 6
src/entt/meta/factory.hpp

@@ -33,7 +33,7 @@ class basic_meta_factory {
     using invoke_type = std::remove_pointer_t<decltype(meta_func_node::invoke)>;
 
     [[nodiscard]] auto &fetch_node() noexcept {
-        return *meta_context::from(*ctx).value[parent];
+        return *meta_context::from(*ctx).bucket[parent];
     }
 
     [[nodiscard]] auto *find_member_or_assert() {
@@ -135,7 +135,7 @@ public:
         : ctx{&area},
           parent{node.info->hash()},
           bucket{parent} {
-        if(auto *curr = meta_context::from(*ctx).value.try_emplace(parent, std::make_unique<meta_type_node>(std::move(node))).first->second.get(); curr->details == nullptr) {
+        if(auto *curr = meta_context::from(*ctx).bucket.try_emplace(parent, std::make_unique<meta_type_node>(std::move(node))).first->second.get(); curr->details == nullptr) {
             curr->details = std::make_unique<meta_type_descriptor>();
         }
     }
@@ -546,9 +546,9 @@ public:
 inline void meta_reset(meta_ctx &ctx, const id_type id) noexcept {
     auto &context = internal::meta_context::from(ctx);
 
-    for(auto it = context.value.begin(); it != context.value.end();) {
+    for(auto it = context.bucket.begin(); it != context.bucket.end();) {
         if(it->second->id == id) {
-            it = context.value.erase(it);
+            it = context.bucket.erase(it);
         } else {
             ++it;
         }
@@ -580,7 +580,7 @@ inline void meta_reset(const id_type id) noexcept {
  */
 template<typename Type>
 void meta_reset(meta_ctx &ctx) noexcept {
-    internal::meta_context::from(ctx).value.erase(type_id<Type>().hash());
+    internal::meta_context::from(ctx).bucket.erase(type_id<Type>().hash());
 }
 
 /**
@@ -603,7 +603,7 @@ void meta_reset() noexcept {
  * @param ctx The context from which to reset meta types.
  */
 inline void meta_reset(meta_ctx &ctx) noexcept {
-    internal::meta_context::from(ctx).value.clear();
+    internal::meta_context::from(ctx).bucket.clear();
 }
 
 /**

+ 2 - 2
src/entt/meta/node.hpp

@@ -272,8 +272,8 @@ auto setup_node_for() noexcept {
 }
 
 [[nodiscard]] inline const meta_type_node *try_resolve(const meta_context &context, const type_info &info) noexcept {
-    const auto it = context.value.find(info.hash());
-    return (it != context.value.end()) ? it->second.get() : nullptr;
+    const auto it = context.bucket.find(info.hash());
+    return (it != context.bucket.end()) ? it->second.get() : nullptr;
 }
 
 template<typename Type>

+ 1 - 1
src/entt/meta/range.hpp

@@ -69,7 +69,7 @@ struct meta_range_iterator final {
     }
 
     [[nodiscard]] constexpr reference operator[](const difference_type value) const noexcept {
-        if constexpr(std::is_same_v<It, decltype(meta_context::value)::const_iterator>) {
+        if constexpr(std::is_same_v<It, typename meta_context::container_type::const_iterator>) {
             return {it[value].first, Type{*ctx, *it[value].second}};
         } else if constexpr(std::is_same_v<typename std::iterator_traits<It>::value_type, meta_base_node>) {
             return {it[value].type, Type{*ctx, it[value]}};

+ 3 - 3
src/entt/meta/resolve.hpp

@@ -38,16 +38,16 @@ template<typename Type>
  * @param ctx The context from which to search for meta types.
  * @return An iterable range to use to visit all meta types.
  */
-[[nodiscard]] inline meta_range<meta_type, decltype(internal::meta_context::value)::const_iterator> resolve(const meta_ctx &ctx) noexcept {
+[[nodiscard]] inline meta_range<meta_type, typename internal::meta_context::container_type::const_iterator> resolve(const meta_ctx &ctx) noexcept {
     const auto &context = internal::meta_context::from(ctx);
-    return {{ctx, context.value.cbegin()}, {ctx, context.value.cend()}};
+    return {{ctx, context.bucket.cbegin()}, {ctx, context.bucket.cend()}};
 }
 
 /**
  * @brief Returns a range to use to visit all meta types.
  * @return An iterable range to use to visit all meta types.
  */
-[[nodiscard]] inline meta_range<meta_type, decltype(internal::meta_context::value)::const_iterator> resolve() noexcept {
+[[nodiscard]] inline meta_range<meta_type, typename internal::meta_context::container_type::const_iterator> resolve() noexcept {
     return resolve(locator<meta_ctx>::value_or());
 }
 

+ 2 - 2
test/entt/meta/meta_type.cpp

@@ -906,7 +906,7 @@ TEST_F(MetaType, Variables) {
 TEST_F(MetaType, ResetAndReRegistrationAfterReset) {
     using namespace entt::literals;
 
-    ASSERT_FALSE(entt::internal::meta_context::from(entt::locator<entt::meta_ctx>::value_or()).value.empty());
+    ASSERT_FALSE(entt::internal::meta_context::from(entt::locator<entt::meta_ctx>::value_or()).bucket.empty());
 
     entt::meta_reset<double>();
     entt::meta_reset<unsigned int>();
@@ -923,7 +923,7 @@ TEST_F(MetaType, ResetAndReRegistrationAfterReset) {
     ASSERT_FALSE(entt::resolve("derived"_hs));
     ASSERT_FALSE(entt::resolve("class"_hs));
 
-    ASSERT_TRUE(entt::internal::meta_context::from(entt::locator<entt::meta_ctx>::value_or()).value.empty());
+    ASSERT_TRUE(entt::internal::meta_context::from(entt::locator<entt::meta_ctx>::value_or()).bucket.empty());
 
     // implicitly generated default constructor is not cleared
     ASSERT_TRUE(entt::resolve<clazz>().construct());