Sfoglia il codice sorgente

meta: further reduce the size of the resolve function

Michele Caini 3 anni fa
parent
commit
ca3ef33f46
2 ha cambiato i file con 10 aggiunte e 10 eliminazioni
  1. 8 3
      src/entt/meta/node.hpp
  2. 2 7
      src/entt/meta/resolve.hpp

+ 8 - 3
src/entt/meta/node.hpp

@@ -148,13 +148,18 @@ template<typename... Args>
     return {};
 }
 
+inline [[nodiscard]] meta_type_node *try_resolve(const type_info &info) noexcept {
+    auto &&context = meta_context::from(locator<meta_ctx>::value_or());
+    const auto it = context.value.find(info.hash());
+    return it != context.value.end() ? &it->second : nullptr;
+}
+
 template<typename Type>
 [[nodiscard]] meta_type_node resolve() noexcept {
     static_assert(std::is_same_v<Type, std::remove_const_t<std::remove_reference_t<Type>>>, "Invalid type");
-    auto &&context = meta_context::from(locator<meta_ctx>::value_or());
 
-    if(auto it = context.value.find(type_id<Type>().hash()); it != context.value.end()) {
-        return it->second;
+    if(auto *elem = try_resolve(type_id<Type>()); elem) {
+        return *elem;
     }
 
     meta_type_node node{

+ 2 - 7
src/entt/meta/resolve.hpp

@@ -51,13 +51,8 @@ template<typename Type>
  * @return The meta type associated with the given type info object, if any.
  */
 [[nodiscard]] inline meta_type resolve(const type_info &info) noexcept {
-    auto &&context = internal::meta_context::from(locator<meta_ctx>::value_or());
-
-    if(auto it = context.value.find(info.hash()); it != context.value.cend()) {
-        return it->second;
-    }
-
-    return {};
+    const auto *elem = internal::try_resolve(info);
+    return elem ? *elem : meta_type{};
 }
 
 } // namespace entt