meta: further reduce the size of the resolve function

This commit is contained in:
Michele Caini
2022-09-12 10:46:32 +02:00
parent 8c4803d906
commit ca3ef33f46
2 changed files with 10 additions and 10 deletions

View File

@@ -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{

View File

@@ -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