meta: rollback safe mode for meta data and functions (perf, not necessary)
This commit is contained in:
2
TODO
2
TODO
@@ -35,6 +35,6 @@ TODO:
|
||||
* meta non-const allow_cast overloads: (const int &) to (int &) is not allowed, but (const int &) to (double &) is allowed (support only for convertibles)
|
||||
* review build process for testbed (i.e. tests first due to SDL)
|
||||
* use any for meta_custom_node
|
||||
* avoid copying meta_type/data/func nodes, and use unique_ptr for meta_custom
|
||||
* avoid copying meta_type nodes, and use unique_ptr for meta_custom
|
||||
* paged vector as a standalone class
|
||||
* resource: shared_from_this?
|
||||
|
||||
@@ -816,8 +816,8 @@ struct meta_data {
|
||||
* @param area The context from which to search for meta types.
|
||||
* @param curr The underlying node with which to construct the instance.
|
||||
*/
|
||||
meta_data(const meta_ctx &area, internal::meta_data_node curr) noexcept
|
||||
: node{std::move(curr)},
|
||||
meta_data(const meta_ctx &area, const internal::meta_data_node &curr) noexcept
|
||||
: node{&curr},
|
||||
ctx{&area} {}
|
||||
|
||||
/**
|
||||
@@ -825,7 +825,7 @@ struct meta_data {
|
||||
* @return The name assigned to the data member, if any.
|
||||
*/
|
||||
[[nodiscard]] const char *name() const noexcept {
|
||||
return node.name;
|
||||
return node->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -833,7 +833,7 @@ struct meta_data {
|
||||
* @return The number of setters available.
|
||||
*/
|
||||
[[nodiscard]] size_type arity() const noexcept {
|
||||
return node.arity;
|
||||
return node->arity;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -841,7 +841,7 @@ struct meta_data {
|
||||
* @return True if the data member is constant, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] bool is_const() const noexcept {
|
||||
return !!(node.traits & internal::meta_traits::is_const);
|
||||
return !!(node->traits & internal::meta_traits::is_const);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -849,7 +849,7 @@ struct meta_data {
|
||||
* @return True if the data member is static, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] bool is_static() const noexcept {
|
||||
return !!(node.traits & internal::meta_traits::is_static);
|
||||
return !!(node->traits & internal::meta_traits::is_static);
|
||||
}
|
||||
|
||||
/*! @copydoc meta_any::type */
|
||||
@@ -865,7 +865,7 @@ struct meta_data {
|
||||
template<typename Type>
|
||||
// NOLINTNEXTLINE(modernize-use-nodiscard)
|
||||
bool set(meta_handle instance, Type &&value) const {
|
||||
return (node.set != nullptr) && node.set(meta_handle{*ctx, std::move(instance)}, meta_any{*ctx, std::forward<Type>(value)});
|
||||
return (node->set != nullptr) && node->set(meta_handle{*ctx, std::move(instance)}, meta_any{*ctx, std::forward<Type>(value)});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -874,7 +874,7 @@ struct meta_data {
|
||||
* @return A wrapper containing the value of the underlying variable.
|
||||
*/
|
||||
[[nodiscard]] meta_any get(meta_handle instance) const {
|
||||
return (node.get != nullptr) ? node.get(meta_handle{*ctx, std::move(instance)}) : meta_any{meta_ctx_arg, *ctx};
|
||||
return (node->get != nullptr) ? node->get(meta_handle{*ctx, std::move(instance)}) : meta_any{meta_ctx_arg, *ctx};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -891,7 +891,7 @@ struct meta_data {
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] Type traits() const noexcept {
|
||||
return internal::meta_to_user_traits<Type>(node.traits);
|
||||
return internal::meta_to_user_traits<Type>(node->traits);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -899,7 +899,7 @@ struct meta_data {
|
||||
* @return User defined arbitrary data.
|
||||
*/
|
||||
[[nodiscard]] meta_custom custom() const noexcept {
|
||||
return {node.custom};
|
||||
return {node->custom};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -907,7 +907,7 @@ struct meta_data {
|
||||
* @return True if the object is valid, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] explicit operator bool() const noexcept {
|
||||
return (node.get != nullptr);
|
||||
return (node != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -916,11 +916,11 @@ struct meta_data {
|
||||
* @return True if the objects refer to the same type, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] bool operator==(const meta_data &other) const noexcept {
|
||||
return (ctx == other.ctx) && (node.set == other.node.set) && (node.get == other.node.get);
|
||||
return (ctx == other.ctx) && (node == other.node);
|
||||
}
|
||||
|
||||
private:
|
||||
internal::meta_data_node node{};
|
||||
const internal::meta_data_node *node{};
|
||||
const meta_ctx *ctx{&locator<meta_ctx>::value_or()};
|
||||
};
|
||||
|
||||
@@ -947,8 +947,8 @@ struct meta_func {
|
||||
* @param area The context from which to search for meta types.
|
||||
* @param curr The underlying node with which to construct the instance.
|
||||
*/
|
||||
meta_func(const meta_ctx &area, internal::meta_func_node curr) noexcept
|
||||
: node{std::move(curr)},
|
||||
meta_func(const meta_ctx &area, const internal::meta_func_node &curr) noexcept
|
||||
: node{&curr},
|
||||
ctx{&area} {}
|
||||
|
||||
/**
|
||||
@@ -956,7 +956,7 @@ struct meta_func {
|
||||
* @return The name assigned to the member function, if any.
|
||||
*/
|
||||
[[nodiscard]] const char *name() const noexcept {
|
||||
return node.name;
|
||||
return node->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -964,7 +964,7 @@ struct meta_func {
|
||||
* @return The number of arguments accepted by the member function.
|
||||
*/
|
||||
[[nodiscard]] size_type arity() const noexcept {
|
||||
return node.arity;
|
||||
return node->arity;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -972,7 +972,7 @@ struct meta_func {
|
||||
* @return True if the member function is constant, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] bool is_const() const noexcept {
|
||||
return !!(node.traits & internal::meta_traits::is_const);
|
||||
return !!(node->traits & internal::meta_traits::is_const);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -980,7 +980,7 @@ struct meta_func {
|
||||
* @return True if the member function is static, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] bool is_static() const noexcept {
|
||||
return !!(node.traits & internal::meta_traits::is_static);
|
||||
return !!(node->traits & internal::meta_traits::is_static);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1004,7 +1004,7 @@ struct meta_func {
|
||||
* @return A wrapper containing the returned value, if any.
|
||||
*/
|
||||
meta_any invoke(meta_handle instance, meta_any *const args, const size_type sz) const {
|
||||
return ((node.invoke != nullptr) && (sz == arity())) ? node.invoke(meta_handle{*ctx, std::move(instance)}, args) : meta_any{meta_ctx_arg, *ctx};
|
||||
return ((node->invoke != nullptr) && (sz == arity())) ? node->invoke(meta_handle{*ctx, std::move(instance)}, args) : meta_any{meta_ctx_arg, *ctx};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1023,12 +1023,12 @@ struct meta_func {
|
||||
/*! @copydoc meta_data::traits */
|
||||
template<typename Type>
|
||||
[[nodiscard]] Type traits() const noexcept {
|
||||
return internal::meta_to_user_traits<Type>(node.traits);
|
||||
return internal::meta_to_user_traits<Type>(node->traits);
|
||||
}
|
||||
|
||||
/*! @copydoc meta_data::custom */
|
||||
[[nodiscard]] meta_custom custom() const noexcept {
|
||||
return {node.custom};
|
||||
return {node->custom};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1036,7 +1036,7 @@ struct meta_func {
|
||||
* @return The next overload of the given function, if any.
|
||||
*/
|
||||
[[nodiscard]] meta_func next() const {
|
||||
return (node.next != nullptr) ? meta_func{*ctx, *node.next} : meta_func{};
|
||||
return (node->next != nullptr) ? meta_func{*ctx, *node->next} : meta_func{};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1044,16 +1044,16 @@ struct meta_func {
|
||||
* @return True if the object is valid, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] explicit operator bool() const noexcept {
|
||||
return (node.invoke != nullptr);
|
||||
return (node != nullptr);
|
||||
}
|
||||
|
||||
/*! @copydoc meta_data::operator== */
|
||||
[[nodiscard]] bool operator==(const meta_func &other) const noexcept {
|
||||
return (ctx == other.ctx) && (node.invoke == other.node.invoke);
|
||||
return (ctx == other.ctx) && (node == other.node);
|
||||
}
|
||||
|
||||
private:
|
||||
internal::meta_func_node node{};
|
||||
const internal::meta_func_node *node{};
|
||||
const meta_ctx *ctx{&locator<meta_ctx>::value_or()};
|
||||
};
|
||||
|
||||
@@ -1588,19 +1588,19 @@ inline bool meta_any::assign(meta_any &&other) {
|
||||
}
|
||||
|
||||
[[nodiscard]] inline meta_type meta_data::type() const noexcept {
|
||||
return (node.type != nullptr) ? meta_type{*ctx, node.type(internal::meta_context::from(*ctx))} : meta_type{};
|
||||
return (node->type != nullptr) ? meta_type{*ctx, node->type(internal::meta_context::from(*ctx))} : meta_type{};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline meta_type meta_data::arg(const size_type index) const noexcept {
|
||||
return index < arity() ? node.arg(*ctx, index) : meta_type{};
|
||||
return index < arity() ? node->arg(*ctx, index) : meta_type{};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline meta_type meta_func::ret() const noexcept {
|
||||
return (node.ret != nullptr) ? meta_type{*ctx, node.ret(internal::meta_context::from(*ctx))} : meta_type{};
|
||||
return (node->ret != nullptr) ? meta_type{*ctx, node->ret(internal::meta_context::from(*ctx))} : meta_type{};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline meta_type meta_func::arg(const size_type index) const noexcept {
|
||||
return index < arity() ? node.arg(*ctx, index) : meta_type{};
|
||||
return index < arity() ? node->arg(*ctx, index) : meta_type{};
|
||||
}
|
||||
|
||||
/*! @cond TURN_OFF_DOXYGEN */
|
||||
|
||||
@@ -131,22 +131,6 @@ struct MetaData: ::testing::Test {
|
||||
|
||||
using MetaDataDeathTest = MetaData;
|
||||
|
||||
TEST_F(MetaData, SafeWhenEmpty) {
|
||||
const entt::meta_data data{};
|
||||
|
||||
ASSERT_FALSE(data);
|
||||
ASSERT_EQ(data, entt::meta_data{});
|
||||
ASSERT_EQ(data.arity(), 0u);
|
||||
ASSERT_FALSE(data.is_const());
|
||||
ASSERT_FALSE(data.is_static());
|
||||
ASSERT_EQ(data.type(), entt::meta_type{});
|
||||
ASSERT_FALSE(data.set({}, 0));
|
||||
ASSERT_FALSE(data.get({}));
|
||||
ASSERT_EQ(data.arg(0u), entt::meta_type{});
|
||||
ASSERT_EQ(data.traits<test::meta_traits>(), test::meta_traits::none);
|
||||
ASSERT_EQ(static_cast<const char *>(data.custom()), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(MetaData, UserTraits) {
|
||||
using namespace entt::literals;
|
||||
|
||||
@@ -193,12 +177,10 @@ TEST_F(MetaData, Name) {
|
||||
ASSERT_EQ(type.data("i"_hs).name(), nullptr);
|
||||
ASSERT_STREQ(type.data("j"_hs).name(), "j");
|
||||
ASSERT_STREQ(type.data("h"_hs).name(), "hhh");
|
||||
ASSERT_EQ(type.data("none"_hs).name(), nullptr);
|
||||
|
||||
ASSERT_EQ(other.data("z"_hs).name(), nullptr);
|
||||
ASSERT_STREQ(other.data("w"_hs).name(), "w");
|
||||
ASSERT_STREQ(other.data("z_ro"_hs).name(), "readonly");
|
||||
ASSERT_EQ(other.data("none"_hs).name(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(MetaData, Comparison) {
|
||||
|
||||
@@ -158,27 +158,6 @@ struct MetaFunc: ::testing::Test {
|
||||
|
||||
using MetaFuncDeathTest = MetaFunc;
|
||||
|
||||
TEST_F(MetaFunc, SafeWhenEmpty) {
|
||||
const entt::meta_func func{};
|
||||
entt::meta_any *args = nullptr;
|
||||
|
||||
ASSERT_FALSE(func);
|
||||
ASSERT_EQ(func, entt::meta_func{});
|
||||
ASSERT_EQ(func.arity(), 0u);
|
||||
ASSERT_FALSE(func.is_const());
|
||||
ASSERT_FALSE(func.is_static());
|
||||
ASSERT_EQ(func.ret(), entt::meta_type{});
|
||||
ASSERT_EQ(func.arg(0u), entt::meta_type{});
|
||||
ASSERT_EQ(func.arg(1u), entt::meta_type{});
|
||||
ASSERT_FALSE(func.invoke({}, args, 0u));
|
||||
ASSERT_FALSE(func.invoke({}, args, 1u));
|
||||
ASSERT_FALSE(func.invoke({}));
|
||||
ASSERT_FALSE(func.invoke({}, 'c'));
|
||||
ASSERT_EQ(func.traits<test::meta_traits>(), test::meta_traits::none);
|
||||
ASSERT_EQ(static_cast<const char *>(func.custom()), nullptr);
|
||||
ASSERT_EQ(func.next(), func);
|
||||
}
|
||||
|
||||
TEST_F(MetaFunc, UserTraits) {
|
||||
using namespace entt::literals;
|
||||
|
||||
@@ -224,7 +203,6 @@ TEST_F(MetaFunc, Name) {
|
||||
ASSERT_EQ(type.func("setter_from_base"_hs).name(), nullptr);
|
||||
ASSERT_STREQ(type.func("getter_from_base"_hs).name(), "getter_from_base");
|
||||
ASSERT_STREQ(type.func("static_setter_from_base"_hs).name(), "static setter");
|
||||
ASSERT_EQ(type.func("none"_hs).name(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(MetaFunc, Comparison) {
|
||||
|
||||
Reference in New Issue
Block a user