* avoid copies from meta_type::invoke (small perf improvement)
* meta_handle::operator* no longer available
* added meta_handle::operator bool
This commit is contained in:
Michele Caini
2021-02-08 11:33:53 +01:00
parent fd989feea3
commit 5c46ccb37e
3 changed files with 9 additions and 9 deletions

View File

@@ -792,11 +792,11 @@ struct meta_handle {
}
/**
* @brief Dereference operator for accessing the contained opaque object.
* @return A meta any that shares a reference to an unmanaged object.
* @brief Returns false if a handle is invalid, true otherwise.
* @return False if the handle is invalid, true otherwise.
*/
[[nodiscard]] meta_any operator*() const {
return any;
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return static_cast<bool>(any);
}
/**
@@ -1550,7 +1550,7 @@ public:
}
}
return (candidate && !ambiguous) ? candidate->invoke(instance, args) : meta_any{};
return (candidate && !ambiguous) ? candidate->invoke(std::move(instance), args) : meta_any{};
}
/**

View File

@@ -746,7 +746,7 @@ TEST_F(MetaAny, ConstConvert) {
TEST_F(MetaAny, UnmanageableType) {
unmanageable_t instance;
entt::meta_any any{std::ref(instance)};
entt::meta_any other = any;
entt::meta_any other = as_ref(any);
std::swap(any, other);

View File

@@ -26,12 +26,12 @@ TEST_F(MetaHandle, Functionalities) {
clazz_t instance{};
entt::meta_handle handle{};
ASSERT_FALSE(*handle);
ASSERT_FALSE(handle);
handle = entt::meta_handle{instance};
ASSERT_TRUE(*handle);
ASSERT_TRUE((*handle).invoke("incr"_hs));
ASSERT_TRUE(handle);
ASSERT_TRUE(handle->invoke("incr"_hs));
ASSERT_EQ(instance.value, 1);
entt::meta_any any{std::ref(instance)};